What will be displyed after the following code is executed?

int x = 0;
System.out.print(x++==++x);
Explanation
- The value of x will be remembered as the left-hand side operand of an expression (i.e. 0)
- A post-increment will be performed after that (i.e., x will take a value of 1)
- A pre-increment will be performed then (i.e., x will take a value of 2)
- Only then the right-hand side operand will be obtained (i.e. 2) leading to a "0 == 2" comparison

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes