Pointer-to-Pointer in C 

Pointer-to-Pointer in C

In this article, I am going to discuss Pointer-to-Pointer in C Program with Examples. Please read our previous articles, where we discussed Arithmetic Operations on Pointers in C Language with Examples.

Pointer-to-Pointer (Chain Pointer) in C:

It is a concept of holding the pointer address into another pointer variable. In C programming language, the pointer to pointer relations can be applied up to 12 stages but generally, there are no limitations. For a pointer variable, we can apply 12 indirection operators. When we are using the pointer to pointer relations then performance will be decreased.

Syntax: *(*p)
pointer datatype *ptr;
p2pointer datatype **ptr;
p2p2pointer datatype ***ptr;
p2p2p2pointer datatype ****ptr;

Example: Pointer to pointer in C
int main ()
    int i = 10;
    int *ptr;
    int **pptr;
    int ***ppptr;
    ptr = &i;
    pptr = &ptr;
    ppptr = &pptr;
    printf ("\n %d %d %d %d", i, *ptr, **pptr, ***ppptr);

Output: 10 10 10 10

For better understanding of the above program, please have a look at the following diagram.

Pointer to pointer in C

How the logic is evaluated in the above Program:

Pointer-to-Pointer (Chain Pointer) in C

Another Program:
void main()
 int a1;
 printf("Enter a value\n");
 scanf("%d", &a1);
 printf("\n%d", *ptr);
 printf("\n%d", **pptr);


Wild Pointer in C

Wild Pointer in C:

Uninitialized pointer variable or the pointer which is not initialized with any variable address is called a wild pointer. The wild pointer is also called a bad pointer because without assigning any variable address, it is pointing to a memory location.

void main()
 int a;
 int *ptr;	//wild or bad pointer

When we are working with pointers, always recommended to initialize with any variable address or make it NULL.

In the next article, I am going to discuss Pointer to Array of functions in C language. Here, in this article, I try to explain Pointer-to-Pointer in C. I hope you enjoy this Pointer-to-Pointer in C article. I would like to have your feedback. Please post your feedback, question, or comments about this article.

Leave a Reply

Your email address will not be published. Required fields are marked *