Conditional Operator

Description
The conditional operator makes the conditional expression evaluate either its second or its third operand, based on the truth value of its first operand. For example :

a ? b : c

If expression a is true, then expression b is evaluated and the result is the value of b. Otherwise, expression c is evaluated and the result is c.

Expressions b and c must be compatible. That is, they must be one of the following:-


 * - both be arithmetic types;
 * - both have the same structure or union type;
 * - both have void type;
 * - both be pointers to compatible types;
 * - one is a pointer and the other a null pointer; or
 * - one is a pointer and the other a void* pointer.

If the first operand (a) of the conditional operator is true, then the third operand (c) is never evaluated.

Similarly, if the first operand (a) is false, then the second operand (b) is never evaluated. The first operand (a) is always evaluated.

Syntax
a ? b : c

Comments
Based on ISO/IEC 9899:TC3 Committee Draft — Septermber 7, 2007, WG14/N1256 6.5.15 Conditional operator and the GNU C Reference Manual