Question Detail

COS 102 test topic Objective Question

Question

Consider the expression: `x = 5; y = ++x;`. What are the final values of `x` and `y`?
Options
A x = 6, y = 6
Correct Answer
B x = 6, y = 5
C x = 5, y = 6
D x = 5, y = 5
Correct Answer

Option A is the correct answer.

Detailed Explanation

The prefix increment ++x increments x to 6 before yielding the value to be assigned to y.

Hint

No hint available

Question Info