【发布时间】:2012-04-25 20:42:24
【问题描述】:
#include<stdio.h>
#include<math.h>
int main()
{
float i = 2.5;
printf("%d\n%d\n%d",i,i,i);
}
当我使用 gcc 编译并运行它时,我得到这个作为输出:
0
1074003968
0
为什么不打印出来
2
2
2
【问题讨论】:
-
您可能还想用
-Wall -Wextra编译您的代码。当我在打开警告的情况下编译该代码时,GCC 抱怨format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’。 -
因为你对 printf() 撒了谎。你告诉它会有 3 个整数,但给了它 3 个浮点数。