int a[]={5,6,7,8}; int *p= a;
Note that in the case of arrays (in most cases), for example, the array a , ADDRESS_OF a matches ADDRESS_OF first element of the .ie array, ADDRESS_OF(a) matches ADDRESS_OF(a[0]) >. & is an ADDRESS_OF statement and, therefore, in the case of an array, a , &a and &a[0] are the same.
I have already emphasized that in most cases the name of the array translates to the address of its first element; one of the notable exceptions is that it is a sizeof operand, which is essential if malloc should work. Another case is that the array name is the operand of the operator and address. Here it is converted to the address of the entire array . Who cares? Even if you think that the addresses will be โthe sameโ in some way, the critical difference is that they are of different types. For an array of n elements of type T, the address of the first element is of type 'pointer to T; the address of the entire array is of type 'pointer to an array of n elements of type T; clearly very different.
Here is an example:
int ar[10]; int *ip; int (*ar10i)[10]; ip = ar; ip = &ar[0]; ar10i = &ar;
For more information, you can refer to The C Book.
source share