我在很多采访中都发现了这个问题,我的老师也问了我同样的问题,主要的疑问是,如果我包括<stdbool.h>
在 C99 标准中,将其评估为 (true)<c
或(false)>c
。需要比链接帖子更明确的答案 --> Usage of greater than, less than operators .
如何a<b<c
或a>b>c
在 C 中评估
例如下面的代码。
# include<stdbool.h>
int main(void){
int a = 1,b=2,c=3;
if(a<b<c)
printf("a great b great c");
}
提前谢谢您。
最佳答案
来自标准itself (关系运算符脚注)
The expression
a<b<c
is not interpreted as in ordinary mathematics. As the syntax indicates, it means(a<b)<c
; in other words, ifa
is less thanb
, compare1
toc
; otherwise, compare0
toc
.
关于c - 如何在 C 中计算 "a<b<c"或 "a>b>c",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47912551/