Here is the snippet from a book:
int y = 5;
int result = y-- * 3 / --y;
System.out.println("y = " + y);
System.out.println("result = " + result);
Assuming increment and decrement have highest precedence, I don't get the explanation:
Order of operations dictates that the multiplication is evaluated first(WHY???). The value
of y is 5, so 5 * 3 is 15. The multiplication is done, so the post - decrement occurs and y
becomes 4. Now the division is evaluated and y is pre - decremented to 3 before the division,
resulting in 15 / 3 , which is 5. The output of this code is:
y = 3
result = 5
Any comments would be appreciated.