In C programming language, a pointer to pointer or double pointer is a variable that holds the address of another pointer.
Given below is the declaration of a pointer to a pointer -
datatype ** pointer_name;
For example int **p;
Here, p is a pointer to Pointer to pointer.
'&' is used for initialization.
For example,
int a = 10; int *p; int **q; p = &a;
The indirect operator (*) is used to access
The following is a double pointer C program-
< p> Live demonstration#include<stdio.h> main ( ){ int a = 10; int *p; int **q; p = &a; q = &p; printf("a =%d ",a); printf(" a value through pointer = %d", *p); printf(" a value through pointer to pointer = %d", **q); }
When the above program is executed, the following results will be produced-
a=10 a value through pointer = 10 a value through pointer to pointer = 10
Now, consider another C program that shows pointer-to-pointer relationships.
Real-time demonstration
#include<stdio.h> void main(){ //Declaring variables and pointers// int a=10; int *p; p=&a; int **q; q=&p; //Printing required O/p// printf("Value of a is %d</p><p>",a);//10// printf("Address location of a is %d</p><p>",p);//address of a// printf("Value of p which is address location of a is %d</p><p>",*p);//10// printf("Address location of p is %d</p><p>",q);//address of p// printf("Value at address location q(which is address location of p) is %d</p><p>",*q);//address of a// printf("Value at address location p(which is address location of a) is %d</p><p>",**q);//10// }
When the above program is executed, the following results will be produced -
Value of a is 10 Address location of a is 6422036 Value of p which is address location of a is 10 Address location of p is 6422024 Value at address location q(which is address location of p) is 6422036 Value at address location p(which is address location of a) is 10
The above is the detailed content of C program to show the relationship between pointers. For more information, please follow other related articles on the PHP Chinese website!