An array designator in expressions is converted (with rare exception) to pointer to its first element.
From the C Standard (6.3.2.1 Lvalues, arrays, and function designators)
3 Except when it is the operand of the sizeof 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’’ that points to the initial
element of the array object and is not an lvalue. If the array object
has register storage class, the behavior is undefined.
And from the C++ Standard (4.2 Array-to-pointer conversion)
1 An lvalue or rvalue of type “array of N T” or “array of unknown
bound of T” can be converted to a prvalue of type “pointer to T”. The
result is a pointer to the first element of the array.
Thus this declaration
double *p1 = array;
is equivalent to
double *p1 = &array[0];
^^^
Consider this demonstrative program
$include <iostream>
int main()
{
double array[] = { 1000.0, 2.0, 3.4, 17.0, 50.0 };
std::cout << "sizeof( array ) = " << sizeof( array ) << std::endl;
std::cout << "sizeof( array + 0 ) = " << sizeof( array + 0 ) << std::endl;
}
The program output is
sizeof( array ) = 40
sizeof( array + 0 ) = 8
In the first output statement the array designator is used as an operand of the sizeof
operator. So there is no conversion from the type double[5]
to double *
.
In the second output statement the array designator is used in expression array + 0
that in turn is used as an operand of the sizeof
operator.
In this case there is conversion from the type double[5]
to the type double *
.