In this tutorial, you will find out about pointer to pointer or twofold pointer in C.
The pointer is utilized to store the memory address of a variable. The twofold pointer is utilized to
store the memory address of some other pointer.
We should attempt to comprehend this by one example.
Pointer to Pointer or Double Pointer in C
As should be obvious in the above example that p1 is a pointer as it holds the memory address of variable a
and p2 is twofold pointer or pointer to pointer as it holds the memory address of pointer p1.
What will be the yield in the event that we attempt to print the estimations of these 3 variables?
printf(“%d”, p1): 5000 (address of a)
printf(“%d”, *p1): 65 (value of a)
printf(“%d”, p2): 6000 (address of p1)
printf(“%d”, *p2): 5000 (address of a)
printf(“%d”, **p2): 65 (value of a)
Beneath program will tell you the best way to utilize twofold pointer in C language.
#include<stdio.h>
int main()
{
int a, *p1, **p2;
a=65;
p1=&a;
p2=&p1;
printf("a = %d\n", a);
printf("address of a = %d\n", &a);
printf("p1 = %d\n", p1);
printf("address p1 = %d\n", &p1);
printf("*p1 = %d\n", *p1);
printf("p2 = %d\n", p2);
printf("*p2 = %d\n", *p2);
printf("**p2 = %d\n", **p2);
return 0;
}
Output:
a = 65
address of a = 2686744
p1 = 2686744
address p1 = 2686740
*p1 = 65
p2 = 2686740
*p2 = 2686744
**p2 = 65
Remark underneath on the off chance that you discovered anything inaccurate or have questions identified with the above tutorial.