The conditional operator ? is a ternary operator (it has three operands) in which the operands are three expressions. It takes the following general form:
expression1 ? expression2 : expression3
For example, consider the following if statement:
-
if (x >= 0) z = cos(x); else z = sin(x);
-
This may be written:
-
z = (x >= 0) ? cos(x) : sin(x);
-
However, the following will not work
-
(getch()=='e')? break:continue;
-
because break and continue are statements and cannot be part of an expression.
The comiler will give an error message such as "expected primary-expression before break"