C程序显示指针与指针之间的关系
在C语言中,指向指针或双指针的指针是一个变量,用于保存另一个指针的地址。
宣言
下面给出的是指向指针的声明-
datatype ** pointer_name;
例如,int**p;
在此,p是指向指针的指针。
初始化
“&”用于初始化。
例如,
int a = 10; int *p; int **q; p = &a;
存取中
间接运算符(*)用于访问
样例程序
以下是双指针的C程序-
#include输出结果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=10 a value through pointer = 10 a value through pointer to pointer = 10
示例
现在,考虑另一个C程序,该程序显示了指针与指针之间的关系。
#include输出结果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\n",a);//10// printf("Address location of a is %d\n",p);//address of a// printf("Value of p which is address location of a is %d\n",*p);//10// printf("Address location of p is %d\n",q);//address of p// printf("Value at address location q(which is address location of p) is %d\n",*q);//address of a// printf("Value at address location p(which is address location of a) is %d\n",**q);//10// }
执行以上程序后,将产生以下结果-
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
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短