As we know by now that a pointer stores the address of the pointed variable. But it is not the only use, pointer also stores the address of another pointer forming a chain like structure.
When we defined the pointer to a pointer, it means the first pointer contains the address of the second pointer and the second pointer contains the address of an actual variable.

We can declare the pointer to pointer variable by simply adding an additional asterisk * before the pointer name. example:
1 | int **pointer_name; |
C++ Program for Pointer to Pointer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> using namespace std; int main () { int num = 100; //Pointer declaration int var; int *ptr1; int **ptr2; //assigning address to pointer ptr1 = # ptr2 = &ptr1; // value present in each varibles cout << "Value stored by var :" << num << endl; cout << "Value stored byt *ptr1 :" << *ptr1 << endl; cout << "Value stored by **ptr2 :" << **ptr2 << endl; return 0; } |
Output: After execution, the following output will be displayed.
1 2 3 | Value stored by var :100 Value stored byt *ptr1 :100 Value stored by **ptr2 :100 |