Alex Rivera | Logout

Is an array name a pointer?

Asked 2009-10-29T06:38:05.200
270

Is an array's name a pointer in C? If not, what is the difference between an array's name and a pointer variable?

Edit
Report

1 Answer

6

An array declared like this

int a[10];

allocates memory for 10 ints. You can't modify a but you can do pointer arithmetic with a.

A pointer like this allocates memory for just the pointer p:

int *p;

It doesn't allocate any ints. You can modify it:

p = a;

and use array subscripts as you can with a:

p[2] = 5;
a[2] = 5;    // same
*(p+2) = 5;  // same effect
*(a+2) = 5;  // same effect
answered 2009-10-29T06:50:14.957

Your Answer