What will be printed to console during the following expression calculation?

int x = 0;
System.out.print(++x==x++);
Explanation
Left side increment will be called before the comparison >>> x = 1
whereas the right side one - after the comparison >>> x = 1.

@geekstomach24 The left operand uses pre-increment (++x) before equals (==) operation. It means the x has value 1 before queals operation. It looks like 1==1. That's why correct answer is the true. The post-increment (x++) will be executed when the entire line is executed System.out.print(++x==x++);. After line System.out.print(++x==x++); the variable x will have value 2.

2023 Jun 5, 9:09:54 AM

interesting

2022 Aug 21, 5:31:21 PM

Please,explain in more detail!

2018 Jun 14, 6:31:28 AM

Follow CodeGalaxy

Mobile Beta

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