Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.
You are here - Home > Programming > C > Basics

Ternary Operators


Ternary operator handles three arguments where first argument is condition, depending upon on that condition it evalutes first or second expression.


condition ? expresssion 1 : expression 2

If condition is true it evalues first expresion else it evalutes second expression. It is just similar to the If-Else statement.


(a>b) ? (c=0) : (c=1);

Same statment can be written as c = (a>b) ? 0 : 1;

Both above statements implements same result but in different way. If a is greater than b then c = 0 else c = 1.

Tip Box

Only one test expression is allowed after '?' and ':' symbol.


Terms of Use | Privacy Policy | Contact Us | Advertise
CodesandTutorials © 2014 All Rights Reserved