鱼C论坛

 找回密码
 立即注册
查看: 1091|回复: 0

[技术交流] 如果两个指针变量指向同一个变量,那么这两个指针的地址则一定相同吗?

[复制链接]
发表于 2020-10-23 13:32:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <iostream>
using namespace std;

int main(void)
{
        int a = 1;
        int b = 1;
        int *pa = &a;
        int *pb = pa;
        int *pc = &a;
        int *pd = &b;
        printf("Address of pa is %p, and address of what pa points is %p\n", pa, &(*pa));
        printf("Address of pb is %p, and address of what pb points is %p\n", pb, &(*pb));
        printf("Address of pc is %p, and address of what pc points is %p\n", pc, &(*pc));
        printf("Address of pd is %p, and address of what pd points is %p\n", pd, &(*pd));
        return 0;
}


输出:

Address of pa: 0x7fff8bada600, address of what pa points: 0x7fff8bada600
Address of pb: 0x7fff8bada600, address of what pb points: 0x7fff8bada600
Address of pc: 0x7fff8bada600, address of what pc points: 0x7fff8bada600
Address of pd: 0x7fff8bada604, address of what pd points: 0x7fff8bada604
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-12 19:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表