edited by
12,435 views
26 votes
26 votes

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)$$

  1. $x=3, y=4, z=2$
  2. $x=6, y=5, z=3$
  3. $x=6, y=3, z=5$
  4. $x=5, y=4, z=5$
edited by

3 Answers

Best answer
29 votes
29 votes

Using option (A) : $x=3, y=4, z=2$

$a=(3>4)?$ No

therefore don't evaluate the first part and check second part $((y>z)?y:z)$

$(4>2)?$ Yes

$a=$ value of $y =4$

Answer is (A) $x=3, y=4, z=2$

edited by
1 votes
1 votes

If we look at the options carefully,

Only Y has the value  , That means we will only go for the expression that results Y (i.e 3rd one)
To execute expression-3, expression-1 has to be false.
For this x<y  , so option A will be true(i.e 3<4)
0 votes
0 votes

The given expression actually finds the max. of 3 integers.
Therefore, the correct option is the one with 4 as the max value.
Therefore, correct opt: (A)

Answer:

Related questions

26 votes
26 votes
2 answers
4
Kathleen asked Sep 12, 2014
13,660 views
If a class $B$ network on the Internet has a subnet mask of $255.255.248.0$, what is the maximum number of hosts per subnet?$1022$$1023$$2046$$2047$