Thanks to Maxim Kartavenkov in particular because pointing out the access violation ended up helping me in the right direction.
Using my example..
#include <stdio.h>
int main()
{
int a[5];
a[1] = 123;
a[2] = 456;
printf("&a is %p\n", &a); printf("a is %p\n", a);
printf("&(&a)[1] is %p\n", &(&a)[1]);
printf("((char*)a) + sizeof(a) is %p\n", ((char*)a) + sizeof a);
int** b = &a;
printf("sizeof(int) is %i\n", sizeof(int));
printf("sizeof(int**) is %i\n", sizeof(int**));
printf("b[1] is %p\n", b[1]);
printf("b[1] is %i\n", b[1]);
return 0;
}
Thus the confusion I had arose from the expectation "that
&a
(where
typeof(a)
is
int[5]
) would be a different pointer address even though that is not what happened".
Maybe
&a
would require creating another variable of type
int**
implicitly as an array on the stack doesn't require such a variable because it can store the elements directly instead? Maybe that is why
&a
instead only returns the same pointer but of a different type, to avoid creating a hidden variable?