What is the output of this C code?
void foo(float *);
int main()
{
int i = 10, *p = &i;
foo(&i);
}
void foo(float *p)
{
printf("%f\n", *p);
}
Answer: B
Correct answer: 0.000000
The four bytes holding the integer 10 are read as an IEEE single-precision float, and that bit pattern is a denormal of about \( 1.4 \times 10^{-44} \), which %f prints as 0.000000. The pointer types are incompatible, so a conforming compiler must issue a diagnostic; older compilers treat it as a warning and produce this output, which is what the question is asking for.
Please log in or register to report this question.