Here is a code which I wrote to test/understand the behavior of pointers of/in an array
int main(void){
int a[4];
memset(a, 0, sizeof(a));
printf("%x %x\n",a,&a);
}
Output of the above program on my machine:
bfeed3e8 bfeed3e8
I can’t understand why are the values a and &a is same. From what I understand &a is supposed to give the address of memory location where a is stored.
What is the explanation for this kind of behavior?
&adoes give you the address ofa.agives youa, which, because it’s an array, decays to a pointer toa.Or to be pedantic, it decays to a pointer to
a[0].