GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 18

Nested conditional computes the maximum

Programming in C · Expressions, Operators & Types · Full GATE CSE 2008 paper

GATE 2008, Q18 1 mark · MCQ
Report issue

Expressions, Operators & Types

Question 18, GATE 2008: Which (x,y,z) makes a=4 in the C expression a=(x>y)?((x>z)?x:z):((y>z)?y:z)?

(A) (3,4,2)
(B) (6,5,3)
(C) (6,3,5)
(D) (5,4,5)
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. If x>y, the expression selects the larger of x and z. Otherwise it selects the larger of y and z. Thus a=max(x,y,z).
2. The maxima for A,B,C,D are respectively 4,6,6,5.
3. Only A yields 4. Equality in a comparison does not change the selected maximum value.

Original paper, page 4