Question 10
Back to Exercise
After int x = 5; int y = x++ + 1;, what are x and y?
- A x = 6, y = 7
- B x = 6, y = 6 Correct
- C x = 5, y = 6
- D x = 5, y = 7
Correct Answer: Option B
x++ contributes the old value 5, so y = 5 + 1 = 6, and x is incremented to 6. (Only one modification of x, so this is well-defined.)
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!