ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
int x = 2;
switch (x) {
case 1: printf("1");
case 2: printf("2");
case 3: printf("3"); break;
default: printf("D");
}- A. 2
- B. 23
- C. 23D
- D. 123
Correct answer: B. 23
Execution jumps to case 2 and then falls through into case 3 because case 2 has no break; the break after case 3 stops before default.
More C Programming questions
- What is printed? c if (-1 < 1u) printf("yes"); else printf("no");
- What is printed? c int a = 0, b = 0; int x = (++a > 5) && (++b > 0); int y = (++a > 0) || (++b > 0); printf("%d %d %d %d", a, b, x, y);
- What is printed? c printf("%c %d %d", 'A' + 2, 'A' + 2, 'z' - 'a');
- What is printed? c unsigned char a = 250, b = 10, z = 0; int s = a + b; unsigned char t = a + b; z--; printf("%d %d %d", t, z, s);
- What is printed? c int x = 6; printf("%d %d", x & 2 == 2, (x & 2) == 2);
- What is printed? c int a = (1, 2, 3); int b = 5; b = (b + 1, b 2); printf("%d %d", a, b);