
在 C 编程语言中,指向指针的指针或双指针是一个保存另一个指针地址的变量。
声明
下面给出的是指向指针的指针的声明 –
datatype ** pointer_name;
例如int **p;
这里,p是一个指向指针的指针。
初始化
‘&’用于初始化。
例如,
int a = 10;int *p;int **q;p = &a;
访问
间接运算符(*)用于访问
示例程序
以下是双指针的C程序 –
现场演示
#includemain ( ){ 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 程序,它显示了指针到指针之间的关系。
实时演示
#includevoid 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程序以显示指向指针之间的关系的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444724.html
微信扫一扫
支付宝扫一扫