I know that arrays in C are just pointers to sequentially stored data. But what differences imply the difference in notation [] and *. I mean in ALL possible usage context.
For example:
char c[] = "test";
if you provide this instruction in a function body it will allocate the string on a stack while
char* c = "test";
will point to a data (readonly) segment.
Can you list all the differences between these two notations in ALL usage contexts to form a clear general view.
According to the C99 standard:
According to the standard declarations
are identical. The contents of the arrays are modifiable. On the other hand, the declaration
defines p with the type as pointer to constant
charand initializes it to point to an object with type constant array ofchar(in C++) with length 4 whose elements are initialized with a character string literal. If an attempt is made to usepto modify the contents of the array, the behavior is undefined.According to 6.3.2.1 Array subscripting dereferencing and array subscripting are identical:
The differences of arrays and pointers are:
More helpful information on the subject can be found at http://www.cplusplus.com/forum/articles/9/