Today I read a C snippet which really confused me:
#include
int
main(void)
{
int a[] = {0, 1, 2, 3};
printf(\"%d\\n\", *(*(&a +
Best to prove it to yourself:
$ cat main.c
#include
main()
{
int a[4];
printf("a %p\n",a);
printf("&a %p\n",&a);
printf("a+1 %p\n",a+1);
printf("&a+1 %p\n",&a+1);
}
And here are the addresses:
$ ./main
a 0x7fff81a44600
&a 0x7fff81a44600
a+1 0x7fff81a44604
&a+1 0x7fff81a44610
The first 2 are the same address. The 3rd is 4 more (which is sizeof(int)). The 4th is 0x10 = 16 more (which is sizeof(a))