为什么低precedence运营商执行的第一?

编程入门 行业动态 更新时间:2024-10-28 18:29:23
本文介绍了为什么低precedence运营商执行的第一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复:结果  问题与运营商precedence

我们知道, precedence preFIX的是不是逻辑更大逻辑与(&放大器;&放)和precedence,大于逻辑或( || )。

we know that precedence of prefix is greater than "LOGICAL AND" (&&) and precedence of "LOGICAL AND" is greater than "LOGICAL OR" (||).

以下活动似乎违背了它:

int main() { int i=-3,j=2,k=0,m; m=++i||++j&&++k; printf("%d %d %d %d",i,j,k,m); return 0; }

如果的 ++ precedence超过&放大器;&安培; 和 || 那么所有的preFIX应首先执行。这个之后我= -2,J = 3,K = 1 然后&放大器;&安培; 将首先执行。为什么输出显示: -2 2 0 1

If precedence of ++ is more than && and || then all prefix should execute first. After this i=-2,j=3,k=1 and then && will execute first. why output shows : -2 2 0 1 ?

该计划的行为也是在Ubuntu v12.04一样的。

The behavior of the program is also same on ubuntu v12.04.

推荐答案

的&放大器;&安培; 和 || 运营商短路。也就是说,如果左边的值是假的&放大器;&安培; 或TRUE为 || 则前不执行右边pression(因为它并不需要确定整个前pression的值)。

The && and || operators are "short-circuiting". That is, if the value on the left is FALSE for && or TRUE for || then the expression on the right is not executed (since it's not needed to determine the value of the overall expression).

更多推荐

为什么低precedence运营商执行的第一?

本文发布于:2023-11-23 23:38:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623197.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:运营商   precedence

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!