LearnFrenzy
Sign in Take a free test

Operators and Expressions · Operators MCQ · Question 10

x = 5; y = x++ + 1; – values of x and y Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links