ConditionalExpression Operator
C has one ternary operator: the conditionalexpression operator (? :).
Syntax
 conditionalexpression:

logicalORexpression
logicalOR expression ? expression : conditionalexpression
The logicalORexpression must have integral, floating, or pointer type. It is evaluated in terms of its equivalence to 0. A sequence point follows logicalORexpression. Evaluation of the operands proceeds as follows:

If logicalORexpression is not equal to 0, expression is evaluated. The result of evaluating the expression is given by the nonterminal expression. (This means expression is evaluated only if logicalORexpression is true.)

If logicalORexpression equals 0, conditionalexpression is evaluated. The result of the expression is the value of conditionalexpression. (This means conditionalexpression is evaluated only if logicalORexpression is false.)
Note that either expression or conditionalexpression is evaluated, but not both.
The type of the result of a conditional operation depends on the type of the expression or conditionalexpression operand, as follows:

If expression or conditionalexpression has integral or floating type (their types can be different), the operator performs the usual arithmetic conversions. The type of the result is the type of the operands after conversion.

If both expression and conditionalexpression have the same structure, union, or pointer type, the type of the result is the same structure, union, or pointer type.

If both operands have type void, the result has type void.

If either operand is a pointer to an object of any type, and the other operand is a pointer to void, the pointer to the object is converted to a pointer to void and the result is a pointer to void.

If either expression or conditionalexpression is a pointer and the other operand is a constant expression with the value 0, the type of the result is the pointer type.
In the type comparison for pointers, any type qualifiers (const or volatile) in the type to which the pointer points are insignificant, but the result type inherits the qualifiers from both components of the conditional.
Examples
The following examples show uses of the conditional operator:
j = ( i < 0 ) ? ( i ) : ( i );
This example assigns the absolute value of i to j. If i is less than 0, i is assigned to j. If i is greater than or equal to 0, i is assigned to j.
void f1( void ); void f2( void ); int x; int y; . . . ( x == y ) ? ( f1() ) : ( f2() );
In this example, two functions, f1 and f2, and two variables, x and y, are declared. Later in the program, if the two variables have the same value, the function f1 is called. Otherwise, f2 is called.