I have a question regarding the precedence of operators in JAVA. I have the following code:
int x = 2;
long y = 1 + x * 4 - ++x;
Viewing the precedence table here .
In my view the expression should be resolved as follows:
1 + x * 4 - 3
1 + 3 * 4 - 3
1 + 12 - 3
y=10
Contrary to what I put in, the response given by the running program is y=6
. Would you like to know why he did the multiplication before the increment?
By the precedence table, increment in my view should be done first.