Programming in C
Programming Fundamentals
GATE 2008
Medium
Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?
a = (x>y) ? ((x>z) ? x : z) : ((y>z) ? y : z)
- x=3, y=4, z=2
- Bx=6, y=5, z=3
- Cx=6, y=3, z=5
- Dx=5, y=4, z=5
Explanation
This expression computes max(x,y,z). Checking each option's maximum: (A) max(3,4,2)=4 ✓. (B) max(6,5,3)=6. (C) max(6,3,5)=6. (D) max(5,4,5)=5. Only (A) gives a=4.
Source: GATE CS 2008 (2008)
This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.