Q:

post increment with addition in Java

I have following code in java
int x=5;
System.out.println(x++ + ++x);

The output is 12.
I thought it should be 11.
We have three operators here:

+ addition
++ (post)
++ (pre)
List item

In which order does the above print statement compile?
If I write int x=5; and then ++x, does x==6 or x==5 as I haven't written x=++x. Does the new value get stored in x?
Looking for a way to remember operator precedence in Java,or .NET, just like we have DMAS. Is their any analogy for this too?

A:

x++ is equal to 5 but x has become 6. ++x means 6 is incremented by 1 that is ++x is 7. So 5 + 7 = 12 is the correct answer.

