Advertisements
Advertisements
Question
Read the
if program segment given below:if(a>b)
z = 25;
else
z = 35;
Which one of the following is the correct conversion of the if program segment to ternary?Options
z = a > b ? 35 : 25;z = a > b ? 25 : 35;z = a > b : 35 ? 25;z = a > b : 25 ? 35;
MCQ
Advertisements
Solution
z = a > b ? 25 : 35;
Explanation:
The ternary operator works in this format:
condition ? expression_if_true : expression_if_false;- Condition:
a > b - True value: In your code, if the condition is true,
zbecomes25. - False value: If the condition is false (
else),zbecomes35.
Putting it together: z = a > b ? 25 : 35;
shaalaa.com
Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
