In this code, the optional result values for the conditional operator, 99.99 (a double) and 9 (an int), are of different types. The result type of a conditional operator must be fully determined at compile time, and in this case the type chosen, using the rules of promotion for binary operands, is double. Because the result is a double, the output value is printed in a floating-point format.
The choice of which of the two values to output is made on the basis of the boolean value that precedes the ?. Since the
test (x > d) is false. This causes the overall expression to take the second of the possible values, which is 9 rather than 99.99. Because the result type is promoted to a double, the output value is actually written as 9.0, rather than the more obvious 9.
If the two possible argument types had been entirely incompatible--for example, (x > d) ? "Hello" : 9--then the compiler would have issued an error at that line.