gpt4 book ai didi

c - 如果我们将打印结构变量本身,程序的行为会是什么

转载 作者:太空宇宙 更新时间:2023-11-04 01:08:35 25 4
gpt4 key购买 nike

我正在检查 C 代码的一些输出。代码是:

main()
{
struct temp
{
int a;
float b;
}t;

t.a = 5;
t.b = 2.0;

printf( "%d %d %f" , t, t.a ,t.b); // printing 5 0 0.0000000 ...why??
printf( "%d %f %d" , t.a, t.b ,t); // printing 5 2.000000 5
}

这个程序的输出是什么? “t”将打印什么?如果此行为未定义,那么是否在某些 C 标准中给出了该行为未定义的情况。

最佳答案

是的,这是一个未定义的行为。这是标准的相应部分:

§ 7.21.6 fprintf 函数

If a conversion specification is invalid, the behavior is undefined. If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined.

关于c - 如果我们将打印结构变量本身,程序的行为会是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17991728/

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