What is the output of the following code snippet? int x = 6;
What is the output of the following code snippet?
int x = 6;
System.out.println(x++ + ++x);
Show answerHide answer
Correct answer: (B) 14
Explanation
x++ gives 6 and makes x 7; ++x then makes x 8 and gives 8. So 6 + 8 = 14.