Conditional Operators in C

The conditional operator also known as ternary operator. It is called ternary operator because it operates on 3 operands.


(exp1) ? exp2 : exp3 ;


  • exp1 is expression that evaluates to true or false.
  • if exp1 is true, exp2 is executed.
  • if exp1 is false, exp3 is executed.


int x=10; y=20;
int max = (x > Y) ? x : y;

In above example. first (x > y) is evaluated and result is false (as 10 > 20 is false). So exp3 is executed (i.e. y ) and y value is copied to max. 

Banner to

Hide Page Information
Conditional Operators in c