In code:
static int a[3] = {1, 2, 3};
The type for a is not a pointer, but an array from int. However, it is automatically converted to a pointer, for example. in standard C:
Unless it is an operand of the sizeof operator or a unary operator & or a string literal used to initialize an array, an expression that is of type `` an array of type is converted to an expression with a pointer of type '' to indicate that it points to the initial element of an array object and is not an lvalue.
So, if a is an array, then = {1, 2, 3} is initialization, not some kind of separate array. I do not know whether it is specified somewhere exactly, but in this sense it is used throughout the standard.
Modify to eliminate confusion by some readers: according to the quoted standard, if you write:
int arr[4] = { }; arr[0] = 1; //arr here has here type int* size_t sz = sizeof(arr); //here it is not type int*, sizeof is exception
peenut
source share