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)$$
Note: " ? : " operator associativity is Right to Left. Only Assignment, Unary & ?: operator are right to left. Rest all are left to right.
@Ahwan link is not working.
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$
convert to if-else
if(x>y)
{ if(x>z) a=x;
else a=z;
}
else{
if(y>z) a=y;
option:-
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)