Conditional Operator

The Conditional Operator is a ternary operator which requires three operands for its operation. The Conditional Operator is denoted by ?: symbol. There are three parts in Conditional Operator. First part is Expression or Condition, Second part is true block and third part is false block.

(Expression or Condition) ? (true block) : (false block)


Consider A = 20 and B = 10
(A>B) ? A : B      would result A i.e 20

Program example of conditional operator

//An example of conditional operator

int main()
    int A=20, B=10;
    printf("%d",((A>B) ? A : B));
    return 0;