Read the if program segment given below:

ICSE Class 10 Computer Applications PYQ · 2026 Paper · Section A

1(vi)1 Mark · 2026 · Section A · 2026 Paper

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?

Show SolutionHide Solution↓

z = a > b ? 25 : 35;

Reason — The ternary operator follows the format condition ? value_if_true : value_if_false. In the given if-else statement, when a > b is true, z is assigned 25, otherwise it is assigned 35. Hence, the correct equivalent ternary expression is z = a > b ? 25 : 35;.

← Previous questionNext question →

Browse the free Computer Applications sample bank