可能重复:结果 问题与运营商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运营商执行的第一?
发布评论