Pointer to a Pointer in C Programming

A pointer to a pointer in C programming is a pointer variable which is used to store the address of another variable. A pointer can store the address of another pointer variable also like any other data type pointer.

A pointer to a pointer means, first pointer will contains the address of second pointer and second pointer can will contain the add of actual value stored in memory.

We use double * operator to define a pointer to a pointer.

<data_type> **<identifier>;

For Example

int count = 10;
int *ptr = &count; /* Pointer to an integer variable */
int **ptrToPtr = &ptr; /* Pointer to a pointer */ 

To access the value of count variable using pointer variable ‘ptr’, we need one asterisk operator(*) like

*ptr;

and to access the value of count variable using pointer to a pointer variable ‘ptrToPtr’, we need two asterisk operator(*) like

**ptrToPtr;

first asterisk returns the memory address stored inside pointer ‘ptr’ and second asterisk retrieves the value stored at memory location pointer by ‘ptr’.

C program to show the use of pointer to a pointer

Pointer to a Pointer in C Programming

#include <stdio.h>
#include <conio.h>
 
int main () {
   int count = 10;
   /* pointer to an integer variable */
   int *ptr = &count;
   /* pointer to a pointer*/
   int **ptrToPtr = &ptr;
    
   printf("Value of count variable = %d\n", count);
   printf("Value of count variable retreived uisng ptr %d\n", *ptr);
   printf("Value of count variable retreived uisng ptrToPtr = %d\n", **ptrToPtr);
 
   getch();
   return 0;
}

Output

Value of count variable = 10
Value of count variable retreived uisng ptr 10
Value of count variable retreived uisng ptrToPtr = 10