Pointer vs Array in C

Pointers and array most of the time are treated as same in c. Some differences are:


  • &pointer = returns the address of pointer.

  • &array = returns the address of first element.

sizeof operator:

  • sizeof(array) = returns the total memory consumed by the all the elements of the array.

  • sizeof(pointer) = returns the only memory consumed by the pointer variable itself.

Array variable can’t be re-assigned a value whereas pointer variable can.


int a[]; //array
Int *p; //pointer

Let us consider that there is an integer pointer variable

int *i;

Now let us consider the outcome of the following assignments –

a = &i; //illegal assignment. a variable can not be updated or modified.
p = &i; //legal assignment.