MCQ Practice Single Best Answer Topic: ICSE Computer Application - Class X - Selection Examination - 2024-25 - MCQ - CALCUTTA PUBLIC SCHOOL

Q Rewrite the code using the ternary operator:

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

Question ID
#23886
Subchapter
ICSE Computer Application - Class X - Selection Examination - 2024-25 - MCQ - CALCUTTA PUBLIC SCHOOL
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is 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: 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

Share this MCQ with your friends or study group.