Suppose a, b, c and d are int variables. For ternary operator in C ( ? : ), pick the best statement.
(A) a>b ? : ; is valid statement i.e. 2nd and 3rd operands can be empty and they are implicitly replaced with non-zero value at run-time.
(B) a>b ? c=10 : d=10; is valid statement. Based on the value of a and b, either c or d gets assigned the value of 10.
(C) a>b ? (c=10,d=20) : (c=20,d=10); is valid statement. Based on the value of a and b, either c=10,d=20 gets executed or c=20,d=10 gets executed.
(D) All of the above are valid statements for ternary operator.
Explanation: For ternary operator, both 2nd and 3rd operands are necessary. So A) isn’t correct. As per operator precedence, ternary operator has higher precedence over assignment operator. So B) isn’t correct.
Quiz of this Question