将float分配给int变量不会引起任何警告 [英] assigning float into int variable causes no warning
本文介绍了将float分配给int变量不会引起任何警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,给出以下代码:
int main(void) {
int i;
i = 12.1234;
i++;
return 0;
}
我编译了代码,我期望并希望编译器给我一个警告,但事实并非如此.我的编译器配置错误吗?有没有办法让我的编译器发出警告?
I compiled the code and I expected and wanted the compiler to give me a warning, but it didn't. Is my compiler configured wrong? Is there a way to make my compiler give warning?
这就是我用的
cc -Wall test.c
cc -Wall test.c
推荐答案
浮点值可以分配给一个整数变量,但是当编译器强制将浮点值分配为整数.
A float value can be assigned to an integer variable but an implicit conversion occurs when compiler forces a float value to be assigned as an integer.
在将浮点值分配给整数后,浮点值中小数点后的数字会丢失.
The digits after the decimal notation in the float value get lost after assigning a float to an integer.
转换->转换
感谢R ..
这篇关于将float分配给int变量不会引起任何警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文