如果 foo == 13
为 false,此代码是否具有明确定义的行为?
if (foo == 13 && ++bar > 42)
{
...
}
最佳答案
是的。如果第一个条件为假,则永远不会评估第二个条件。
参见 Avoiding the execution of second expression's side effects .
关于c - 无用条件下的变量修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13541274/