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);- A. 1 1
- B. 0 0
- C. 1 0
- 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
- Assume 4-byte int. What is printed? c printf("%d %d", sizeof(int) -1 < 0, (int)sizeof(int) -1 < 0);
- What is printed? c Bool b = 0.5; printf("%d %d", b + 2, (Bool)256);
- What is printed? c int c = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (j == 1) break; c++; } printf("%d", c);
- With 4-byte int, what is printed? c int a[4] = {1, 2, 3, 4}; char c = (char )a; int p = (int )(c + 8); printf("%d %td", p, p - a);
- What does Staticassert(sizeof(long) >= 8, "need 64-bit long"); do in C11?
- What is printed? c int i = 0, s = 0; do { if (++i == 3) continue; if (i == 5) break; s += i; } while (i < 10); printf("%d %d", s, i);