HitBrother

Pointers To Pointers In C language

pointer to pointer

Pointers To Pointers

Pointers store the address of a variable, similarly the address of a pointer can also be stored in some other pointer.

Definition Of Pointer To Pointer

A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value as shown below.

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 Of Pointers To Pointers In C Language

main ( )
{
int a=5;
int *p1; /*pointer to an integer*/
int **p2; /*pointer to pointer to an integer*/
int ***p3; /*pointer to pointer to pointer to an integer*/
p1= &a;
p2= &p1;
p3 =&p2;
printf(“%d”,a); /*output = 5*/
printf(“%d”,*p1); /*output = 5*/
printf(“%d”,**p2); /*output = 5*/
printf(“%d”,***p3); /*output = 5*/
printf(“%u”,*p2); /*address of p1 will be printed*/
}

Advertisement

Video Of Pointer To Pointer

Advertisement