"... it's just a pointer ..."? No. An array is not a pointer. An array is an array object: a continuous continuous block of memory in which the elements of the array are stored, without any pointers. In your case, the array has 6 elements in size 4 each. This is why your sizeof
is rated to 24.
A common misconception regarding pointer arrays has been debunked millions of times, but for some reason it appears all the time. Read the FAQ, come back if you have any questions about this.
http://c-faq.com/aryptr/index.html
PS As Jojim Pileborg correctly noted in his answer, sizeof
not a function. This is the operator.
Another context in which arrays behave differently than pointers is the unary operator &
("operator address"). When unary &
is applied to an int *
pointer, an int **
pointer is created. When unary &
is applied to an array of type int [10]
, a pointer of type int (*)[10]
. These are two different types.
int *p = 0; int a[10] = { 0 }; int **p1 = &p; int **p2 = &a; int (*p3)[10] = &a;
This is another popular source of questions (and errors): sometimes people expect &
create an int **
pointer when applied to an int [10]
array int [10]
.
source share