All mock tests are FREE till 31 December — register to save your progress

Consider the following statements:
int x = 10, y = 15;
x = ((x == y) ? (y + x) : (y - x));
What will be the value of x after executing these statements?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. 5

Explanation

x == y is false (10 ≠ 15), so the conditional operator evaluates y − x = 15 − 10 = 5.

More Programming Languages and Computer Graphics questions