在下面的示例中,如果取消注释float f = 0.0;,
并将 替换return(0.0 ? 1 : 0);为return(f ? 1 : 0);。
输出是NIL。
这是我的代码:
/* file main.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
cl -W4 -MTd -O2 -TC main.c -Fetest */
#include <stdio.h>
int my_func(void)
{
/* float f = 0.0; */
return(0.0 ? 1 : 0);
}
int main(void)
{
printf("%s\n", ( my_func() ? "ONE" : "NIL") );
return 0;
}
在 32 位 Windows 机器上,使用 Visual Studio 此代码输出:
ONE
- 为什么
my_func()返回值true(1) ? - C 编译器如何解释这个表达式
(0.0 ? 1 : 0)?