gpt4 book ai didi

c - 使用 %f 打印整型变量

转载 作者:太空狗 更新时间:2023-10-29 17:07:20 25 4
gpt4 key购买 nike

以下 c 程序的输出是:0.000000

输出背后是否有逻辑,或者答案是否依赖于编译器,或者我只是得到一个垃圾值?

#include<stdio.h>

int main()
{
int x=10;
printf("%f", x);
return 0;
}

PS:- 我知道尝试使用 %f 打印整数值是愚蠢的。我只是从理论上问这个问题。

最佳答案

来自最新C11 draft§7.16 Variable arguments <stdarg.h> :

§7.16.1.1/2

...if type is not compatible with the type of the actual next argument 
(as promoted according to the default argument promotions), the behavior
is undefined, except for the following cases:

— one type is a signed integer type, the other type is the corresponding
unsigned integer type, and the value is representable in both types;
— one type is pointer to void and the other is a pointer to a character type.

关于c - 使用 %f 打印整型变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11673503/

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