Possible Duplicate:
C: How come an array’s address is equal to its value?
Could someone maybe help me explain array decaying? In specific, I was confused about 1) how does an array refer to itself, and 2) is it true that, when I define
int array[] = { 45, 67, 89 };
then array, &array,and &array[0] all refer to this array? I found out they appear as the same outputs when printed, but are they also referring to exactly the same thing in memory?
array, in value contexts is a of typeint *, and the pointer points to the first element of the array.&array, is of type “pointer to an array [3] ofint” and points to the wholearray.&array[0]is of typeint *, and points to the first element of the array.So,
&array[0]is the same asarray, ifarrayis used in value context. One situation wherearrayis not used in value context is insizeofoperator. So:sizeof arraywill be different fromsizeof &array[0].Let’s take an example:
See also: http://web.torek.net/torek/c/pa.html