gpt4 book ai didi

c - 使用 %f 格式说明符打印 int

转载 作者:行者123 更新时间:2023-11-30 18:39:04 25 4
gpt4 key购买 nike

我想知道为什么输出为 0.000000。我知道使用 float 格式说明符打印 int 或使用 b 类型使用值类型会给出许多地方所写的未指定行为。我引用一下

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

但它总是给出 0.000000,必须在寄存器或汇编代码中定义一些内容。

简而言之,我想知道是什么原因导致对于任何 i 值,输出始终为 0.000000?

#include<stdio.h>
int main()
{
int i=10;
printf("%f\n",i);
return 0;
}

都说我知道 i 的值可能在输出中的某个地方,但由于进动窗口大小,它不会显示在控制台上。如果我使用 %e 我得到 enter image description here

最佳答案

您可能一天会得到相同的结果,第二天会得到另一个结果,这就是关于 undefined behavior 的全部故事。 。标准不保证未定义行为的任​​何确定性结果。

使用 printf 打印时应使用正确的类型说明符

关于c - 使用 %f 格式说明符打印 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31319739/

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