array
, in value contexts is a of type int *
, and the pointer points to the first element of the array. &array
, is of type "pointer to an array [3] of int
" and points to the whole array
. &array[0]
is of type int *
, and points to the first element of the array.
So, &array[0]
is the same as array
, if array
is used in value context. One situation where array
is not used in value context is in sizeof
operator. So: sizeof array
will be different from sizeof &array[0]
.
Let's take an example:
int array[] = { 45, 67, 89 };
int *pa = array; /* pa is now pointing to the first element of "array" */
int *pb = &array[0]; /* pb is also pointing to the same */
int (*pc)[3] = &array; /* pc points to the whole array.
Note the type is not "int *" */
printf("%zu\n", sizeof &array[0]); /* prints size of an "int *" */
printf("%zu\n", sizeof array); /* prints 3 times the size of an int */
printf("%zu\n", sizeof &array); /* prints size of pointer to an array[3] of int */
See also: http://web.torek.net/torek/c/pa.html