Programming in "C‟ | Define the terms pointer and pointer to array. Also write two advantages of pointer.

Definition :

Pointer:

Pointer is a variable that stores the address of another variable which is of similar data type. Eg: 

int i=3; 

int *ptr = &i; 

Here the address of i is stored in the pointer variable ptr. 

Pointer to array:

An array name is a constant pointer to the first element of the array. 

Eg int arr[5], *p;

then p=arr; 

Here p acts as pointer to array 'arr'.

Advantages of using pointer: 

(i)   It allows passing of arrays and strings to functions more efficiently. 

(ii)  It makes possible to pass address of structure instead of entire structure to the functions.

(iii) It makes possible to return more than one value from the function. 

(iv)  It supports dynamic memory management  


Post a Comment

0 Comments