ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
unsigned int i;
int count = 0;
for (i = 3; i >= 0; i--) {
if (++count == 5) break;
}
printf("%d %u", count, i); /* 32-bit unsigned int */- A. 4 0
- B. 5 0
- C. 5 4294967295
- D. 4 4294967295
Correct answer: C. 5 4294967295
i >= 0 is always true for an unsigned value, so without the break this would loop forever. Counts 1–4 happen at i = 3, 2, 1, 0; then i-- wraps to 4294967295 (UINT_MAX) and count reaches 5 there.
More C Programming questions
- What is printed? c printf("%d %d %d %d", -17 / 5, -17 % 5, 17 / -5, 17 % -5);
- What is printed? c int i = 5; sizet s = sizeof(i++); printf("%zu %d", s, i); / 4-byte int /
- What is printed? c char names[] = {"Ann", "Bob", "Cy"}; printf("%c %s %zu", names[1][0], names[2], strlen(names[0]));
- What is printed? c int n = 40; / binary 101000 / printf("%d %d %d", n & (n - 1), n & -n, (n & (n - 1)) == 0);
- What is printed? c int a[] = {3, 1, 4, 1, 5}; int sum(int n) { return n == 0 ? 0 : a[n - 1] + sum(n - 1); } int main(void) { printf("%d"…
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers and double, natural alignment). What is printed? c int a[3][4] = {{1, 2, 3, 4}, {5…