In C programming language, if the first and the second operands of operator + are of types int and float, respectively, the result will be of type
Answer: B
Correct answer: float
The usual arithmetic conversions apply: when the operands of a binary operator have different types, the one of lower rank is converted to the type of the other before the operation, and the result has that common type.
Here int is converted to float, so the addition is performed in floating point and the result is float. The rule is why integer division is such a common source of surprise - 1/2 is 0 because both operands are int, whereas 1/2.0 is 0.5.
Please log in or register to report this question.