What is printed by this C code: printf(“%d”, (int)-3.99);?
Correct answer B. -3
Explanation
Converting a floating value to an integer type discards the fractional part, which means truncation towards zero rather than rounding. So -3.99 becomes -3, not -4. The value -4 would come from floor(-3.99) and the result is not -3.99 because the cast produces an int. If the truncated value does not fit in the target type the behaviour is undefined, but -3 fits easily.
Answer checked How we write and check questions
Discussion