c - 如何在 C 中计算 "a<b<c"或 "a>b>c"

标签 c

我在很多采访中都发现了这个问题,我的老师也问了我同样的问题,主要的疑问是,如果我包括<stdbool.h>在 C99 标准中,将其评估为 (true)<c(false)>c 。需要比链接帖子更明确的答案 --> Usage of greater than, less than operators .

如何a<b<ca>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, if a is less than b, compare 1 to c; otherwise, compare 0 to c.

关于c - 如何在 C 中计算 "a<b<c"或 "a>b>c",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47912551/

相关文章:

C: vsprintf 覆盖数组

c - 为什么内核在访问 32 位系统的内核模块中的系统调用表后会出现 panic ?

c - NTP 客户端无限循环(不工作)

c++ - 同时包含 C 和 C++ 文件的项目

python - 斐波那契数列在 python 中有效,但在 c 中无效?

计算C中随机生成器的数量

c - 我的函数调用有什么问题?

c - 我需要找到 2 个字符串中的重复字符

c++ - 大型项目的 Emacs 教程

c - 如何破解弱化的 TEA 分组密码?