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?