Hi, I'm messing around with multidimensional arrays and pointers. I've been looking at a program that prints out the contents of, and addresses of, a simple array. Here's my array declaration:
int zippo[4][2] = { {2,4},
{6,8},
{1,3},
{5,7} };
My current understanding is that zippo
is a pointer, and it can hold the address of a couple of other pointers. By default, zippo
holds the address of pointer zippo[0]
, and it can also hold the addresses of pointers zippo[1]
, zippo[2]
, and zippo[3]
.
Now, take the following statement:
printf("zippo[0] = %p\n", zippo[0]);
printf(" *zippo = %p\n", *zippo);
printf(" zippo = %p\n", zippo);
On my machine, that gives the following output:
zippo[0] = 0x7fff170e2230
*zippo = 0x7fff170e2230
zippo = 0x7fff170e2230
I perfectly understand why zippo[0]
and *zippo
have the same value. They're both pointers, and they both store the address (by default) of the integer 2, or zippo[0][0]
. But what is up with zippo
also sharing the same memory address? Shouldn't zippo
be storing the address of the pointer zippo[0]
? Whaaaat?