pointer vs arrays

Hello,

I'm trying to understand pointers a little better and have a question hopefully someone can answer.

So, arrays are pointers, great. But there must be something additional than just saying they are pointers. Here is why I ask that.

If I define an array and a pointer:

int my_array[10];
int *my_pointer;

I can do this:

my_pointer = my_array;

but I CAN'T do this:

my_array = my_pointer;

I imagine it has to do with the addresses set aside for each. But if someone can explain it I would appreciate it.

Thanks.
Assigning my_array to a pointer has the pointer hold the address to the first element in the array - the address of my_array[0].
So, arrays are pointers, great.

Arrays are definitely not pointers. In many contexts an array name acts as a pointer to the first element, but that doesn't make the array a pointer.

I agree. That is the reason for the question. Many references do say that arrays are pointers but perhaps similar is more accurate.

But the question is what are the details behind the difference.

They are similar enough that I can set my_pointer = my_array but not the other way around.

Does anyone here have the details under the covers to explain?

Thanks.
closed account (48T7M4Gy)
http://stackoverflow.com/questions/3959705/arrays-are-pointers
Topic archived. No new replies allowed.