C Primer Plus (5th Edition)

I l @ ve RuBoard

The Conditional Operator

? : takes three operands, each of which is an expression. They are arranged this way: expression1 ? expression2 : expression3 . The value of the whole expression equals the value of expression2 if expression1 is true, and equals the value of expression3 otherwise .

Examples

( 5 > 3 ) ? 1 : 2 has the value 1 .

( 3 > 5 ) ? 1 : 2 has the value 2 .

( a > b ) ? a : b has the value of the larger of a or b .

I l @ ve RuBoard

Категории