English

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? - Computer Applications

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, z becomes 25.
  • False value: If the condition is false (else), z becomes 35.

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
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×