Possible Duplicate:
Is array name a pointer in C?
So, I usually declare arrays using pointers.
However, you can also declare arrays using square brackets notation:
char a[] = "ok" ;
char b[] = "to" ;
char *pa = a ;
cout << "a " << sizeof( a ) << endl ; // 3
cout << "pa " << sizeof( pa ) << endl ; // 4
The peculiar thing is, sizeof( a )
will be the actual size of the array in bytes, and not the size of a pointer.
I find this odd, because where is the pointer then? Is a square bracket-declared array actually a kind of datastructure with (sizeof(char)*numElements)
bytes?
Also, you cannot re-assign a to b:
a = b ; // ILLEGAL.
Why is that? It seems as though a is the array and not a pointer to the array ("left operand must be l-value" is the error for a = b
above). Is that right?