我尝试在 C 中运行以下代码:
#include <stdio.h>
int main() {
int a = 10, b = 5, c = 5;
int d;
d = b + c == a;
printf("%d", d);
}
我得到的输出为d = 1
。有人可以向我解释一下当我们像这样使用 ==
时会发生什么吗?
最佳答案
§6.5.9 (== and !=)-http://c0x.coding-guidelines.com/6.5.9.html
The == (equal to) and != (not equal to) operators are analogous to the relational operators except for their lower precedence.)Each of the operators yields 1 if the specified relation is true and 0 if it is false. The result has type int. For any pair of operands, exactly one of the relations is true.
因此,这里 b+c
等于 a
,因为两者的值都是 10
,因此它会产生 1
.
关于c - 当我们任意使用 == 时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31500404/