gpt4 book ai didi

c - 打印指针值

转载 作者:行者123 更新时间:2023-12-04 11:51:44 25 4
gpt4 key购买 nike

#include <stdio.h>

int main(void)
{
int x = 99;
int *pt1;

pt1 = &x;

printf("Value at p1: %d\n", *pt1);
printf("Address of p1 (with %%p): %p\n", pt1);
printf("Address of p1 (with %%d): %d\n", pt1);

return 0;
}

使用 %d 而不是 %p 的打印机指针值有什么缺点/危险?

最佳答案

%d 显示一个整数 - 指针的大小不需要等于整数的大小。

关于c - 打印指针值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5418728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com