DRAFT
ConditionalOperatorNotExpression
Misconception:
The syntax cond ? expr1 : expr2
is just an alternative for the if
statement and is not an expression.
Incorrect
The conditional operator is not an expression
Correct
The conditional operator is not an expression
CorrectionHere is what's right.
Here is what's right.
The conditional operator (often called “ternary operator”) is an expression and, as a such, evaluates to a certain value.
In a case like cond ? expr1 : expr2
, the whole expression evaluates to whatever expr1
evaluates to when cond
is true
and to whatever expr2
evaluates to when cond
is false
.