Skip to content
doubtly

2 answers

Answer: condition ? expression1 : expression2;

The conditional operator ?: is the only ternary operator in C (it takes three operands).

  • The condition is evaluated first.
  • If it is true (non-zero), expression1 is evaluated and becomes the value of the whole expression.
  • If it is false (zero), expression2 is 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?

Your answer

Log in or create a free account to answer this question.