Arrays are not pointers. Except when it is the operand of the sizeof
or unary &
operators, or is a string literal used to initialize another array in a declaration, an expression of type "N-element array of T
" will be converted ("decay") to an expression of type "pointer to T
", and the value of the expression will be the address of the first element of the array.
Given the declaration of A
, all of the following are true:
Expression Type Decays to Value
---------- ---- --------- -----
A int [3][4] int (*)[4] &A[0][0]
*A int [4] int * &A[0][0]
&A int (*)[3][4] n/a &A[0][0]
A[i] int [4] int * &A[i][0]
*A[i] int n/a A[i][0]
&A[i] int (*)[4] n/a &A[i][0]
A
decays to an expression of type "pointer to 4-element array of int
". A[i]
decays to an expression of type "pointer to int
. The address of the first element of the array is the same as the address of the array itself, so the expressions
A
*A
&A
A[0]
&A[0]
&A[0][0]
all evaluate to the same value, but the types of the expressions will be different.