array names are not the same thing as pointers.
Okay...
think of arrays as being their own type. Like
int foo[2];
is really of type int[2], which is different from type int.
So:
1 2 3 4 5 6 7 8 9 10 11 12
|
typedef int int2[2]; // typedef
// pointers to arrays work like pointers to any other type
// a point to an int looks like this:
int an_int;
int* a_ptr;
a_ptr = &an_int;
// so pointers to arrays would work exactly the same:
int2 an_array;
int2* a_ptr;
a_ptr = &an_array;
|
Where this gets tricky is that C and C++ let you implicitly cast an array name to a pointer of the element type. So if you have an int2 type, you can cast an int2 to an int*:
1 2 3 4
|
int2 an_array;
int* a_ptr;
a_ptr = an_array; // OK
a_ptr = &an_array[0]; // equivilent way to do the same thing
|
So while array names are not really the same as pointers, you can
cast them to pointers. Note however that they cast to the
element type, not the array type.
IE: int2 is an array of ints, so you can get a pointer to an int, but you can't get a pointer to an int2 without the & operator.
EDIT: corrected my code.. forgot a * somewhere