ProgrammingHardWipro · Capgemini pattern

What is printed?

What is printed?
float f = 0.1f, g = 0.5f;
printf("%s ", f == 0.1 ? "eq" : "ne");
printf("%s", g == 0.5 ? "eq" : "ne");
  1. A. ne eq
  2. B. eq eq
  3. C. eq ne
  4. D. ne ne

Correct answer: A. ne eq

0.1 has no exact binary form: the float holds about 0.100000001, and when promoted to double for the comparison it differs from the double 0.1, so ne. 0.5 = 1/2 is exact in both types, so eq.

More C Programming questions

Exams that ask this topic