ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
int x = 2;
switch (x) {
case 1: printf("A");
case 2: printf("B");
case 3: printf("C"); break;
default: printf("D");
}- A. BCD
- B. B
- C. ABC
- D. BC
Correct answer: D. BC
Control jumps to case 2 and, without a break, falls through into case 3, printing B then C; the break there stops it before default. Only the matched case and those after it run.
More C Programming questions
- What is printed? c int n = 5; while (n-- > 2) printf("%d", n); printf(" %d", n);
- Given int x = 1, y = 2; const int p = &x; int const q = &x; which pair of statements both fail to compile?
- What is printed? c enum { A, B = 5, C, D = 2, E }; printf("%d %d %d", A, C, E);
- With 4-byte int, what is printed? c int a[] = {1, 2, 3}; char p = (char )a; p += 4; printf("%d", (int )p);
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d %d", ((a + 1) + 2), a + 1);
- What is printed? c int x = 3; if (x = 0) printf("A%d", x); else printf("B%d", x);