ProgrammingVery hardProduct company OA

Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed?

Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed?
int big = 16777217;          /* 2^24 + 1 */
float f = big;
printf("%d", (int)f == big);
  1. A. 16777217
  2. B. Undefined behaviour
  3. C. 1
  4. D. 0

Correct answer: D. 0

A float holds 24 significant bits, so integers above 2^24 are not all representable; 2^24 + 1 rounds to 2^24 = 16777216. Converting back gives 16777216, which is not equal to big. The conversion is well defined because the value is in range for float.

More C Programming questions

Exams that ask this topic