Pointer to a Pointer
We know that, a pointer is a variable that holds the address of another variable. In the similar way, a pointer to a pointer is a variable that holds the address of a pointer.
Hence, a pointer to a pointer is the chain of pointers. Only one pointer holds the value of a particular variable pointed to, and the double pointer holds the address of the pointer. It can be represented as:
Pointer to a Pointer in C
An example of a pointer to a pointer is:
Pointer to a pointer Example in C
In the above example, pptr is the pointer to a pointer, but not **pptr.
Hence, a pointer to a pointer is the chain of pointers. Only one pointer holds the value of a particular variable pointed to, and the double pointer holds the address of the pointer. It can be represented as:
![Pointer to a pointer in C | Coder's Lap](/media/course/c/pointer-to-pointer.png)
An example of a pointer to a pointer is:
int num = 10;
int *ptr = #
int **pptr = &ptr;
It can be represented as:
int *ptr = #
int **pptr = &ptr;
![Pointer to a pointer Example in C | Coder's Lap](/media/course/c/pointer-to-pointer-example.png)
Pointer to a Pointer Example
C
#include <stdio.h>
int main()
{
int num = 10;
int *ptr = #
int **pptr = &ptr;
printf("The value of num = %d\n", num);
printf("The address of num = %d\n", ptr);
printf("The address of ptr = %d\n", pptr);
printf("The value of *ptr = %d\n", *ptr);
printf("The value of **ptr = %d\n", **pptr);
return 0;
}
int main()
{
int num = 10;
int *ptr = #
int **pptr = &ptr;
printf("The value of num = %d\n", num);
printf("The address of num = %d\n", ptr);
printf("The address of ptr = %d\n", pptr);
printf("The value of *ptr = %d\n", *ptr);
printf("The value of **ptr = %d\n", **pptr);
return 0;
}
Output
The value of num = 10
The address of num = 2000
The address of ptr = 5566
The value of *ptr = 10
The value of **ptr = 10
The address of num = 2000
The address of ptr = 5566
The value of *ptr = 10
The value of **ptr = 10