java地址和值的区别_检查函数的指针地址和值

我是C的初学者并且正在阅读一本名为“理解和使用C指针”的书,并最终遇到了使用printf函数的问题 .

当使用debug_p时,事实证明指针num_p的地址不同但在调试中精确到num,但是当在main()中尝试printf时它返回正确的值 .

我的问题是,为什么会这样呢?是否有合适的方法在函数内执行printf并具有正确的指针地址?

#include

void debug(int num)

{

printf("Address of num: %i Value: %i\n", &num, num);

}

void debug_p(int *num_p)

{

printf("Address of num_p: %i Value %i\n", &num_p, num_p);

}

int main()

{

int num=11;

int *num_p=#

printf("Address of num: %i Value: %i\n", &num, num);

printf("Address of num_p: %i Value: %i\n\n", &num_p, num_p);

debug(num);

debug_p(num_p);

return 0;

}

main()的输出:

Address of num: 2358860 Value: 11

Address of num_p: 2358848 Value: 2358860

从debug输出,然后是debug_p:

Address of num: 2358816 Value: 11

Address of num_p: 2358816 Value 2358860

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值