C防爆Ex pression评价 [英] Evaluation of C expression
本文介绍了C防爆Ex pression评价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int main() {
int i = -3, j = 2, k = 0, m;
m = ++i || ++j && ++k;
printf("%d %d %d %d\n", i, j, k, m);
return 0;
}
我认为这和放大器;&安培;有更多的precedence该||按照这个逻辑 ++Ĵ
应该执行,但它从来不和节目输出 -2 2 0 1
。这里发生了什么?什么是中间步骤?
i thought that && has more precedence that || as per this logic ++j
should execute, but it never does and the program outputs -2 2 0 1
. What is going on here? What are the intermediate steps?
推荐答案
&放大器;&安培;
确实有更高的precedence比 ||
,这意味着 ++我|| ++ J&安培;&安培; ++氏/ code>解析为
++我|| (++ J&安培;&安培; ++ K)
&&
does have higher precedence than ||
, which means that ++i || ++j && ++k
parses as ++i || (++j && ++k)
.
然而,这并不能改变一个事实,即的RHS ||
只执行,如果LHS返回 0
。
However this does not change the fact that the RHS of ||
only executes if the LHS returns 0
.
precedence不会影响评价的顺序。
Precedence does not affect order of evaluation.
这篇关于C防爆Ex pression评价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文