Because the variable t declared as having an array type
int t[3];
then sizeof( t ) gives a value equal to 3 * sizeof( int )
C standard (6.5.3.4 sizeof and alignof operators)
2 The sizeof operator gives the size (in bytes) of its operand,
and indeed an array with three elements of type int takes up memory equal to bytes in 3 * sizeof( int ) .
In expressions with rare exceptions that are used in the sizeof operator descriptor, converters are converted to pointers to their first elements.
Thus, if you use, for example, the following expression
sizeof( t + 0 )
then t in the expression t + 0 will be converted to a pointer, and you will get that sizeof( t + 0 ) is equal to the size of the pointer to int on your platform, which is 8 .
From the C standard (6.3.2.1 Lvalues, arrays and function notation)
3 Except when it is an operand of the sizeof operator or the unary & operator or is a string literal used to initialize an array, an expression that is of type '' array of type is converted to an expression of type '' pointer to a type that points to the initial element of the object array and is not an lvalue value. If the array object has a register storage class, the behavior is undefined.
Vlad from Moscow
source share