#include <stdio.h>
int main() {
int y = 1;
if (y & (y = 2))
printf("true %d\n",y);
else
printf("false %d\n",y);
return 0;
}
输出是如何出现的 true 2
?据我里面的if
这种情况会发生if( 1 & (2))
但输出为 true 2
.
最佳答案
在表达式 y&(y=2)
中,您同时读取和写入 y
,两者之间没有序列点。这样做会调用 undefined behavior 。这意味着无法准确预测程序的行为,因此没有答案是“正确的”。
关于c - if (y & (y = 2) 那么如何处理这个if条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52096796/