一元运算符的运算符优先级或最大Munch规则排在第一位 [英] Operator precedence or Maximal Munch Rule comes first for Unary Operators
本文介绍了一元运算符的运算符优先级或最大Munch规则排在第一位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这里有以下代码:
int a,b,x;
a=b=1;
x=a+++b;
现在,x
的值将为2,因为先将a
进行后递增,然后将其添加到b
.
Now the value of x
will be 2 as a
is first being post incremented and then it is being added to b
.
下面是编译后的字节码:
Following is the compiled byte code :
0 iconst_1
1 dup
2 istore_2 [b]
3 istore_1 [a]
4 iload_1 [a]
5 iinc 1 1 [a]
8 iload_2 [b]
9 iadd
10 istore_3 [x]
因此表达式将等同于x = (a++) + b
.
现在,另一个表达式x=a++++b
由于最大munch规则而无法编译.它将变为x = (a++) ++ b
,因此会出现编译错误.
Now the other expression x=a++++b
, won't compile because of the maximal munch rule. It will become x = (a++) ++ b
and hence compilation error.
x=a+++b
的上述行为是由于优先级 ++还是由于最大限制规则?
Is the above behavior of x=a+++b
because of the precedence of the operator ++ or because of maximal munch rule?
推荐答案
查看全文