首页 > 后端开发 > C++ > 正文

C程序以显示指向指针之间的关系

PHPz
发布: 2023-09-08 23:45:02
转载
1437人浏览过

c程序以显示指向指针之间的关系

在 C 编程语言中,指向指针的指针或双指针是一个保存另一个指针地址的变量。

声明

下面给出的是指向指针的指针的声明 -

datatype ** pointer_name;
登录后复制

例如int **p;

这里,p是一个指向指针的指针。

初始化

'&'用于初始化。

例如,

int a = 10;
int *p;
int **q;
p = &a;
登录后复制

访问

间接运算符(*)用于访问

芦笋演示
芦笋演示

一键出成片的录屏演示软件,专为制作产品演示、教学课程和使用教程而设计。

芦笋演示 34
查看详情 芦笋演示

示例程序

以下是双指针的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=10
a value through pointer = 10
a 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</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//
}
登录后复制

输出

当执行上述程序时,会产生以下结果 -

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
登录后复制

以上就是C程序以显示指向指针之间的关系的详细内容,更多请关注php中文网其它相关文章!

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号