This can be used to replace the statements of the form if-then-else. The conditional operator, ?:, is unique in C in that it is a ternary operator. This means that the operator connects three operands. The first operand is always evaluated first. It is usually a
Conditional expression that uses the logical operators. The next two operands are any other valid expressions, which can be single constants, variables or general expressions.
The complete conditional expression consists of all three operands connected by the conditional operator symbols? and:
Conditional expressions are only useful in replacing if-else statements when the expressions in the equivalent if-else statement are not long or complicated. For example, the statement
Grade = salary> 10000? A: B;
is a one-line statement whose longer or equivalent form is
if (salary > 10000)
Grade = A;
else
Grade = B;