Consider the following code segment: int x = 22, y = 15;
Consider the following code segment:
int x = 22, y = 15;
x = (x>y) ? (x+y) : (x−y);
What will be the value of x after the code is executed?
Show answerHide answer
Correct answer: (B) 37
Explanation
Since 22 > 15 is true, the conditional operator picks x + y = 22 + 15 = 37, which is assigned to x.