ProgrammingVery hardProduct company OA · GATE CS

Assume IEEE-754 single-precision float and 32-bit unsigned int. What is printed?

Assume IEEE-754 single-precision float and 32-bit unsigned int. What is printed?
union { float f; unsigned u; } v = {1.0f};
printf("%08X", v.u);
  1. A. 7F800000
  2. B. 40000000
  3. C. 00000001
  4. D. 3F800000

Correct answer: D. 3F800000

1.0 is sign 0, exponent 127 (the bias) and fraction 0: 0 01111111 000…0, which is 0x3F800000. 0x40000000 is 2.0 and 0x7F800000 is infinity. Reading another union member reinterprets the bytes; it does not convert 1.0 to the integer 1.

More C Programming questions

Exams that ask this topic