CodesandTutorials
Home   Programming   Hardware   Networking
 
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.  

C Categories

Ternary Operators

« Previous Point - Increment & Decrement Operators Next Chapter - Functions »

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.


« Previous Point - Increment & Decrement Operators Next Chapter - Functions »

Tip Box

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


Advertisement

Rate Website
   

 


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