Is there a situation when an array is not converted to pointer except of sizeof?
From C99/C11, section 6.3.2.1:
Except when it is the operand of the sizeof
operator, [the _Alignof
operator,] or the unary &
operator, or is a string literal used to initialize an array, an expression that has type "array of type" is converted to an expression with type "pointer to type"...
Note that _Alignof
is only in C11.
Is there any other similar situation where it matters whether I use an array or a pointer?
The above rule explains everything about the behaviour of arrays vs. pointers. However, there are several less-than-obvious implications of the conversion it describes.
For example, this doesn't compile:
void foo(int **a) { }
int b[5][10];
foo(b); // Compilation error; b becomes &b[0], which is pointer type,
// and thus doesn't then become &&b[0][0]
And neither does this:
int a[5];
int b[5];
a = b; // Compilation error; a becomes &a[0], which isn't an lvalue