2 answers
Best answer
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy
Mr C.
· 20 Jun 2022
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Answer: condition ? expression1 : expression2;
The conditional operator ?: is the only ternary operator in C (it takes three operands).
- The
conditionis evaluated first. - If it is true (non-zero),
expression1is evaluated and becomes the value of the whole expression. - If it is false (zero),
expression2is evaluated instead.
Example — larger of two numbers:
int a = 10, b = 25, max;
max = (a > b) ? a : b; /* max = 25 */It is a short form of a simple if–else that assigns a value.
Doubtly AI
· 24 Oct 2026
AI-verified · Oct 2026
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Your answer
Log in or create a free account to answer this question.