Possible Duplicate:
C: How come an array’s address is equal to its value?
C pointer : array variable
Considering a multidimensional Array:
int c[1][1];
Why all of the following expression points to the same address??
printf("%x", (int *) c); // 0x00000500
printf("%x", *c); // 0x00000500
printf("%x", c); // 0x00000500
How would a pointer’s actual value and it’s derefernced value can be the same?
Under most circumstances1, an expression of type “N-element array of
T” will be converted (“decay”) to expression of type “pointer toT“, and the value of the expression will be the address of the first element in the array.The expression
chas typeint [1][1]; by the rule above, the expression will decay to typeint (*)[1], or “pointer to 1-element array ofint“, and its value will be the same as&c[0]. If we dereference this pointer (as in the expression*c), we get an expression of type “1-element array ofint“, which, by the rule above again, decays to an expression of typeint *, and its value will be the same as&c[0][0].The address of the first element of the array is the same as the address of the array itself, so
&c==&c[0]==&c[0][0]==c==*c==c[0]. All of those expressions will resolve to the same address, even though they don’t have the same types (int (*)[1][1],int (*)[1],int *,int (*)[1],int *, andint *, respectively).1 – the exceptions to this rule are when the array expression is an operand of the
sizeof,_Alignof, or unary&operators, or is a string literal being used to initialize another array in a declaration