Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Pointer vs Array in C



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.
Updated on: 2019-07-30T22:30:25+05:30

432 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements