public class Test {
public static void main(String[] args) {
int x = 3;
int y = ++x * 5 * x--;
System.out.println("x is " + x);
System.out.println("y is " + y);
}
}
The output is:
x is 3
y is 80
But using the rule that post-operators take precedence over pre-operators, shouldn't it be like this:
y = ++x * 5 * 3 (x is 2)
y = 3 * 5 * 3 (x is 3)
y = 45
Instead, this code is acting as if it just evaluated the expression from left-to-right, evaluating the pre-increment before the post-decrement. Why?