我指的是问题“ "IF" argument evaluation order? ”以了解 c++ 中“if”语句的评估顺序。
这是 if 语句中的条件以错误的顺序求值的代码。
#include <iostream>
using namespace std;
int main()
{
int t = 0;
if((1 / t) == 1 && t != 0)
{
cout << "0" << endl;
}
cout << "1" << endl;
return 0;
}
结果为 1 而不是浮点异常。
最佳答案
被零除是未定义的行为。任何事情都有可能发生。
If the second operand of / or % is zero the behavior is undefined.
关于c++ - "if"c++ 中的语句不从左到右计算条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52620983/