Pointer vs Array in C

CServer Side ProgrammingProgramming

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

&operator:

  • &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.

Declaration:

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.
raja
Published on 29-Mar-2019 11:06:55
Advertisements