ProgrammingHardProduct company OA

Assume IEEE-754 double. What is printed?

Assume IEEE-754 double. What is printed?
printf("%d %d", 0.1 + 0.2 == 0.3, 0.5 + 0.25 == 0.75);
  1. A. 1 1
  2. B. 0 0
  3. C. 1 0
  4. D. 0 1

Correct answer: D. 0 1

0.1, 0.2 and 0.3 have no exact binary form, and the rounded sum 0.1 + 0.2 lands on 0.30000000000000004, one step away from the stored 0.3. 0.5, 0.25 and 0.75 are sums of powers of two, exact in binary, so that comparison is true.

More C Programming questions

Exams that ask this topic