Question Detail

COS 102 test topic Objective Question

Question

What are the values of `x` and `y` after executing `x = 5; y = x++;`?
Options
A x = 6, y = 5
Correct Answer
B x = 6, y = 6
C x = 5, y = 5
D x = 5, y = 6
Correct Answer

Option A is the correct answer.

Detailed Explanation

The postfix operator assigns the current value of x (5) to y, then increments x to 6.

Hint

No hint available

Question Info