使用:
float return1(void);
int main()
{
int x;
x = (float)return1();
printf("%f",x);
return 0;
}
float return1()
{
return 1;
}`
为什么输出是-0.000000
?
不应该将x
隐式转换为float
并打印1.000000
吗?
最佳答案
Shouldn't x be implicitly cast to a float and print 1.000000?
不,不应该,因为编译器可能不知道 printf
的作用或将使用哪种格式来打印 x
。
x
的类型为 int
,因此应使用 %d
而不是 %f
来打印它。
关于c - 隐式和显式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33217916/