ICSE Class 10 Computer Applications
Question 1 of 30
Solved Sample Paper 2 — Question 1
Back to all questions 1
Question Question 1(i)
Consider the following code snippet
if (c > d)
x = c;
else
x = d;Choose the correct option if the code mentioned above is rewritten using the ternary operator.
- x = (c > d) ? c : d;
- x = (c > d) ? d : c;
- x = (c > d) ? c : c;
- x = (c > d) ? d : d;
x = (c > d) ? c : d;
Reason — Correct syntax of ternary operator is:
variable = (test expression) ? exp 1 : exp 2
If the test expression is true, exp 1 is assigned to variable, else exp 2 is assigned to the variable.