C Multiple Indirection

This section illustrates you the concept of Multiple
Indirection.
C permits the pointer to point to another pointer.
This creates many layers of pointer and therefore called as multiple
indirection. A pointer to a pointer has declaration is similar to
that of a normal pointer but have more asterisk sign before them. This indicates
the depth of the pointer. You can see in the given example, we have declared an
integer variable i initialized to 100. The statement int ** pt creates a
pointer which points to pointer to a variable with int value. We
have passed the value of i to pointer pt2 and to pass the value of pt2
to pt1, we have used the statement pt1 = &pt2; which shows the
Multiple Indirection.
Here is the code:
MULTINDI.C
#include <stdio.h>
#include <conio.h>
void main() {
int i =100;
int **pt1;
int *pt2;
clrscr();
pt2 = &i;
pt1 = &pt2;
printf("The value of **pt1 = %d \n The value of *pt2 = %d", **pt1, *pt2);
getch();
}
|
Output will be displayed as:

Download the source code

|