-->

Pointer to Pointer

Pointer to Pointer
Pointer to Pointer
A pointer to a pointer is a form of multiple indirections, or a chain of pointer.
Normally, a pointer contains the address of a variable. When we define a pointer to pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value:

A variable that is a pointer to a pointer must be declared as such.
This is done by placing an additional asterisk in front of its name.

Example:
int **var;
When a target value is indirectly pointed to by a pointer to a pointer, accessing that value requires that the asterisk operator be applied twice.

A C example program to explain how pointer to pointer concept works.

#include<stdio.h>
int main()
{
int var;
int *ptr;
int **pptr;
var=1000;
ptr=&var; //ptr now has address of var
pptr=&ptr; //pptr now has address of ptr
printf(“Value for var=%d\n”,var); //value of var
printf(“Value available at *ptr=%d\n”,*ptr); //value of var again i.e. value in the address pointed by ptr
printf(“Value available at **pptr=%d\n”,**pptr); //Again value of var i.e. value at address given by the value in the address pointed by pptr
return();
}

OUTPUT
Value of var = 1000
Value available at *ptr =1000
Value available at **pptr = 1000



Related Posts

Subscribe Our Newsletter