在 c 编程语言中,指向指针的指针或双指针是一个保存另一个指针地址的变量。
声明下面给出的是指向指针的指针的声明 -
datatype ** pointer_name;
例如int **p;
这里,p是一个指向指针的指针。
初始化'&'用于初始化。
例如,
int a = 10;int *p;int **q;p = &a;
访问间接运算符(*)用于访问
示例程序以下是双指针的c程序 -
现场演示
#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);}
输出当执行上述程序时,会产生以下结果 -
a=10a value through pointer = 10a value through pointer to pointer = 10
示例现在,考虑另一个 c 程序,它显示了指针到指针之间的关系。
实时演示
#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
",a);//10// printf("address location of a is %d
",p);//address of a// printf("value of p which is address location of a is %d
",*p);//10// printf("address location of p is %d
",q);//address of p// printf("value at address location q(which is address location of p) is %d
",*q);//address of a// printf("value at address location p(which is address location of a) is %d
",**q);//10//}
输出当执行上述程序时,会产生以下结果 -
value of a is 10address location of a is 6422036value of p which is address location of a is 10address location of p is 6422024value at address location q(which is address location of p) is 6422036value at address location p(which is address location of a) is 10
以上就是c程序以显示指向指针之间的关系的详细内容。