C Tutorial Ternary operator
If Statement
Ternary Operator

Switch Statement
While Loop
Do-While Loop
For Loop
Break
Continue

 
 
 

 

Home
 

 

Following is the ternary opereator

The conditional expression can be used as a shorthand for some if-else statements. The

general syntax of the conditional operator is:

 

<expression1> ? <expression2> : <expression3>

 

 

This is an expression, not a statement, so it represents a value. The operator works by evaluating expression1. If it is true (non-zero), it evaluates and returns expression2 . Otherwise, it evaluates and returns expression3.

 

The classic example of the ternary operator is to return the smaller of two variables. Every once in a while, the following form is just what you needed. Instead of...

 

if (x < y) {

min = x;

}

else {

min = y;

}

You just say...

 

min = (x < y) ? x : y;

 

 

Want To Know more with Video ???