When the array variable is considered as pointer and when it is considered as simple array in C? As example sometimes sizeof(array_variable) operator returns the address size and sometimes it returns the size of the array.
4 Answers
C 2011 (N1570) 6.3.2.1 3:
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’’ 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.
C 2011 (N1570) 6.7.6.3 7:
A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation.

- 195,579
- 13
- 168
- 312
In a function argument, an array ([]
) or [...]
) is equivalent to a pointer (*
). So sizeof(myarg) == sizeof(void*)
is true for void f(char *myarg);
, void f(char myarg[]);
and void f(char myarg[42]);
.
In global and local variables, an array is different from a pointer. sizeof(...)
reflects that difference.
An array can always be converted to a pointer automatically (but not the other way round), and the address of the first element is used, i.e. ary
is converted to &ary[0]
.

- 80,836
- 20
- 110
- 183
-
+1 for mentioning the special case of array syntax being used in function arguments. – Barmar Sep 10 '13 at 15:59
-
The C standard does not guarantee that the sizes of pointers to different types are the same. – Eric Postpischil Sep 10 '13 at 17:47
Always it is treated as pointer . when you use array name without index , it will give the base address of the array . When you use the array name with index , it will be treated as *(array name + index) . It gives the indexe-th element from the base address . *array means first element .

- 21,904
- 13
- 74
- 138
name of an array variable is always a pointer. It is the specilization of sizeof()
that it returns the size of an array if applied to an array variable.

- 3,319
- 2
- 22
- 33
-
C does not have specializations. `sizeof` is an operator, not a function. It produces the size of an array when applied to an array expression, not just an array variable. – Eric Postpischil Sep 10 '13 at 17:55