The ternary operator "?:" is sometimes called a conditional operator.
For conditional expression b?x:y, the condition B is evaluated first and then judged. If the value of B is true, the value of x is computed and the result of the operation is the value of x, otherwise, y is computed with a value of Y. A conditional expression never computes X, and also calculates Y. The conditional operator is associated to the right, that is, the grouping is computed from left to right. For example, an expression a?b:c?d:e will be executed in A?b: (c?d:e).
?: The second and third operands control the type of the conditional expression. Set X and Y to be the type of the second and third operands, respectively, then:
If x and Y are the same type, then the type is the type of the conditional expression.
Otherwise, if there is an implicit conversion from X to Y, but there is no conversion of Y to X, then Y is the type of the conditional expression.
Otherwise, if there is an implicit conversion from Y to X, but there is no conversion of x to Y, then X is the type of the conditional expression.
Otherwise, no expression type is defined, and a compile-time error occurs.