The concept of the pointer can be extended further. As we have seen earlier, a pointer variable can be assigned the address of an ordinary variable. Now, this variable itself could be another pointer. This means that a pointer can contain the address of another pointer.
The declaration of a pointer-to-pointer looks like
int **ipp;
Where the two asterisks indicate that two levels of pointers are involved.
The following program will make you the concept clear.
/* Program that declares a pointer to a pointer */ # include<stdio.h> main( ) { int i = 100; int *pi; int **pii; pi = &i; pii = π printf ("Address of i = %u \n", &i); printf ("Address of i = %u \n", pi); printf ("Address of i = %u \n", *pii); printf ("Address of pi = %u \n", &pi); printf ("Address of pi = %u \n", pii); printf ("Address of pii = %u \n", &pii); printf ("Value of i = %d \n", i); printf ("Value of i = %d \n", *(&i)); printf ("Value of i = %d \n", *pi); printf ("Value of i = %d", **pii); }
OUTPUT
Address of i = 65524
Address of i = 65524
Address of i = 65524
Address of pi = 65522
Address of pi = 65522
Address of pii = 65520
Value of i = 100
Value of i = 100
Value of i = 100
Value of i = 100
Consider the following memory map for the above shown example: