Discussion
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.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development