ProgrammingVery hardProduct company OA
What is printed?
What is printed?
_Bool b = 0.5;
printf("%d %d", b + 2, (_Bool)256);- A. 2.5 1
- B. 3 1
- C. 2 0
- D. 3 0
Correct answer: B. 3 1
Converting any non-zero scalar to _Bool gives 1 and zero gives 0, with no truncation: 0.5 becomes 1, so b + 2 = 3. (_Bool)256 is also 1. An 8-bit unsigned char would have turned 256 into 0, which is the trap.
More C Programming questions
- 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);
- What is printed? c struct N { int v; struct N nx; }; void del(struct N h, int x) { while (h) { if ((h)->v == x) h = (h)->nx; else h =…
- What is printed? c int rot(const char a, const char b) { char buf[32]; if (strlen(a) != strlen(b)) return 0; strcpy(buf, a); strcat(buf…