The conditional operator is also known as "Ternary Operator". The conditional operator contains a condition followed by two statements or values. If the condition is true, the first statement is executed, otherwise the second statement is executed.
Syntax:
CONDITION ? EXPRESSION-1 : EXPRESSION-2;
Example:
a==0 ? printf("A is Zero") : printf("A is Not Zero");
Note:
The additional use of conditional operator is "SELECTIVE ASSIGNMENT".
Programming Examples
void main() |
We know that the general form of the conditional operator is condition ? true part : false part. This form can also be interpreted as:
If condition then statement else statement
The nesting of conditional operator generally in two forms.