【发布时间】:2013-11-22 05:39:12
【问题描述】:
代码sn-p的o/p:
printf("%f", 9/5);
-
在我的 linux gcc 4.6.3 中(gcc myprog.c 后跟 ./a.out):
-0.000000
-
在 codepad.org 中:
2.168831
为什么不一样?
我已经引用了链接:Why cast is needed in printf? 和 Implicit conversion in C?,但无法使用它。
有关键盘执行的信息: C:GCC 4.1.2 标志:-O -fmessage-length=0 -fno-merge-constants -fstrict-aliasing -fstack-protector-all
编辑: 更多的: 用于在(在同一程序中)键盘中执行以下操作
printf("%f\n", 99/5);
printf("%f\n", 18/5);
printf("%f\n", 2/3);
printf("%f\n%f\n%f", 2, 3, 4);
printf("%f\n", 2);
o/p 是
2.168831
2.168831
2.168831
0.000000
0.000000
-0.001246
-0.0018760.000000
前三个输出是相同的垃圾值(而不是最后一个)。想知道为什么。
【问题讨论】:
-
GCC 4.4.7 产生:前 4 个 printfs 为 0.000000,最后一个为 0.0000000.000000。
标签: c gcc type-conversion printf