Question 3
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
float f = 16777217;
printf("%.0f\n", f);
return 0;
}
- A 16777217
- B 16777218
- C 1.67772e+07
- D 16777216 Correct
Correct Answer: Option D
2²⁴ + 1 needs 25 significant bits, but a float has 24. It is rounded to the nearest representable value, 16 777 216 (a tie, broken towards the even mantissa). Compilers even warn that the constant changes value.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!