ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int s = 0;
for (int i = 0; i < 6; i++) {
switch (i % 4) {
case 0: s += 1;
case 1: s += 2; break;
case 2: continue;
default: s += 10;
}
s *= 2;
}
printf("%d", s);- A. 448
- B. 224
- C. 216
- D. 112
Correct answer: B. 224
break leaves only the switch; continue inside a switch belongs to the enclosing loop and skips s *= 2. i = 0: case 0 falls through into case 1 → 3, doubled 6. i = 1: 8 → 16. i = 2: continue, s stays 16 (not doubled). i = 3: default → 26 → 52. i = 4: 55 → 110. i = 5: 112 → 224. 448 doubles on i = 2 as well (treating continue like break); 216 forgets the fall-through from case 0.
More C Programming questions
- What is printed? c int calls; int f(int n) { calls++; return n < 3 ? n : f(n - 1) + f(n - 3); } int main(void) { int r = f(8); printf("%d…
- What is printed? c char s[] = "aaabccdddd"; char r = s, w = s; while (r) { char c = r; int n = 0; while (r == c) { r++; n++; } w++ = c; if…
- Assume 32-bit unsigned int. What is printed? c unsigned int x = 0x5Cu; / 0101 1100 / unsigned int low = x & -x; unsigned int y = x + low…
- Assume 4-byte int with 4-byte alignment. What is printed? c struct P { char tag; int v; }; struct P a[4] = {{'a', 1}, {'b', 2}, {'c', 3}…
- Assume plain char is signed 8-bit, two's complement, and EOF is −1. What is printed? c char c = 'xff'; printf("%d %d %d %d", c == 0xFF…
- Read the declaration: c char ((x)[4])(int); What is x?