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");- A. ne eq
- B. eq eq
- C. eq ne
- 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
- On a little-endian machine with 4-byte int and ASCII, what is printed? c union { int i; char c; } u; u.i = 0x41424344; printf("%c", u.c);
- What is printed? c void swap(int x, int y) { x ^= y; y ^= x; x ^= y; } ... int a = 7; swap(&a, &a); printf("%d", a);
- On a two's-complement machine, what is printed? c printf("%d %d", 40 & -40, 40 & (40 - 1));
- For a signed int n on a two's-complement machine, how many of these are correct? (i) (n & (n - 1)) == 0 is true for every positive power…
- What is printed? c #define DOUBLE(x) x + x printf("%d", 10 / DOUBLE(5) 2);
- Which of a, b, c, d are pointers? c #define IPTR int typedef int IPT; IPTR a, b; IPT c, d;