Following program would state my doubt clearly I think,so I posted the program:
#include <stdio.h>
int main() {
int a[]={1,2,3,4,5};
if(&a[0] == a)
printf("Address of first element of an array is same as the value of array identifier\n");
if(&a == a)
printf("How can a value and address of an identifier be same?!");
return 0;
}
This is the link to output: http://ideone.com/KRiK0
When it is not the subject of the
sizeofor unary&operators, an array evaluates to a (non-lvalue) pointer to its first element.So
&ais the address of the arraya, andaevaluates to the address of the first element in the array,a[0].That the address of the array and the address of the first element in the array are the same is not surprising (that is, they point to the same location even though they have different types); the same is true of
structs as well. Given:Then
&sand&s.xpoint to the same location (but have different types). If converted tovoid *they will compare equal. This is exactly analogous with&aand&a[0](and consequently justa).