Question 56

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?
  1. A22
  2. B37
  3. C7
  4. D37 and 7
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.

From DSSSB TGT Computer Science Practice Set 1

This is question 56 of DSSSB TGT Computer Science Practice Set 1. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.