Home > database >  On the problem of operator precedence
On the problem of operator precedence

Time:09-21

Operator precedence + + should be higher than +
Int y=2;
Int z=3 + + + + + y y y;
If the above statement is y++ first?
That if the first calculate y++, the results should not be z=3 + 3 + 3 + 3=12?
Who is going to give to explain

CodePudding user response:

1, y++ as a unary operator, in contrast, in addition, subtraction, multiplication, and division higher priority
2, when y++ or + + y in the formula, is not the priority calculation directly, or from left to right in turn operation, for example:
Int y=2;
Int z=3 + + + + + y y y;

Z=3 + 2 + 2 + 3=10

For example:
Int y=2;
Int=2 + + + y + z y++;
Int x=y;

Z=2 + 3 + 3=8;
X=4.


  • Related