MCQ Single Best Answer Moderate

QRewrite the code using the ternary operator:

if (c > d) 
    x = c; 
else 
    x = d;

ID: #23886 ICSE Computer Application - Class X - Selection Examination - 2024-25 - MCQ - CALCUTTA PUBLIC SCHOOL 76 views
Question Info
#23886Q ID
ModerateDifficulty
ICSE Computer Application - Class X - Selection Examination - 2024-25 - MCQ - CALCUTTA PUBLIC SCHOOLTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A x = (c > d) ? c : d;
  • B x = (c > d) ? d : d;
  • C x = (c > d) ? c : c;
  • D x = (c > d) ? d : c;
Correct Answer: Option A

Explanation

Explanation:

 

The ternary operator is written as:

x = (condition) ? value_if_true : value_if_false;

In this case, if c > d, assign c to x; otherwise, assign d t

o x.

Share This Question

Challenge a friend or share with your study group.