gpt4 book ai didi

c - 我想了解 c 中 "printf"函数的工作原理。例如,对于下面代码中使用的打印语句,输出不同,为什么?

转载 作者:行者123 更新时间:2023-11-30 20:20:33 26 4
gpt4 key购买 nike

为什么即使使用 %d 也会打印指针

int main()
{
int s=5 ,t ,**p ,*n;
n=&s;
p=&n;
printf("%d",n);
printf("\n%p",*p);
return 0;

}
//answer for first print statement is purely integers
//answer for second one is hexadecimal

最佳答案

这是undefined behavor 。您必须将格式说明符所需的类型与传递的值的类型相匹配。

关于c - 我想了解 c 中 "printf"函数的工作原理。例如,对于下面代码中使用的打印语句,输出不同,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45883942/

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