Ternary Operators


Description

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

Syntax

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.

Example

(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.