简体   繁体   English

有关C语言中的关系运算符的问题?

[英]Question regarding Relational Operator in C?

I am learning C language and I have some question as follows (sorry if these are silly ones) 我正在学习C语言,并且有以下一些问题(对不起,如果很愚蠢的话)

I am using Dev-C++ 4.9.9.2 to run some examples: 我正在使用Dev-C ++ 4.9.9.2运行一些示例:

int m=3, n=4, k = 2;
(1) printf("%d", k<m<n); => this one prints 1
(2) printf("%d", k>m>n); => this one prints 0
(3) printf("%d", m<n>k); => this one prints 0

As the book says "A zero value stands for false and any other value stands for true." 正如书中所说的:“零值代表false,其他任何值代表true”。 So, why the statement (3) prints 0 (false). 因此,为什么语句(3)打印0(false)。 I thought it should be 1, or what am i missing here? 我以为应该是1,或者我在这里想念什么?

Can anyone give me a clear explanation, please? 有人可以给我一个清晰的解释吗?

Thanks a lot. 非常感谢。

According to C's precedence rules, m<n>k gets interpreted as (m<n)>k (your other examples follow the same form). 根据C的优先级规则, m<n>k被解释为(m<n)>k (您的其他示例遵循相同的形式)。 m<n is true, so that evaluates to 1. Then the statement is actually 1>k which is false, thus 0. m<n为真,因此求值为1。则该语句实际上为1>k ,它为假,因此为0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM