Except when it is the operand of the sizeof
or unary &
operator, or is a string literal used to initialize an array in a declaration, an expression of type "N-element of T
" will be converted ("decay") to an expression of type "pointer to T
", and its value will be the address of the first element of the array.
The expression ar
has type "5-element array of int
"; if it's not the operand of the &
operator, it will be converted to type "pointer to int
", and its value will be the address of the first element of the array.
In the expression &ar
, ar
is the operand of the unary &
operator, so the conversion doesn't happen; in this case, the type of the expression is "pointer to 5-element array of int
".
Both ar
and &ar
have the same value (the address of the first element of the array is the same as the address of the whole array), but the types are different:
Expression Type Decays to
---------- ---- ---------
ar int [5] int *
&ar int (*)[5] n/a
ar + 1
will point to the next int
value (it's equivalent to writing &ar[1]
). &ar + 1
will point to the next 5-element array of int
(that is, it will point to the int
value immediately following the last element of the array).
cpp + 1
will point to the next char **
element (equivalent to writing &cp[1]
).