ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int c = 0;
for (int i = 0; i < 5; i++) {
switch (i) {
case 2: break;
default: c++;
}
}
printf("%d", c);
}- A. 3
- B. 2
- C. 4
- D. 5
Correct answer: C. 4
The break exits only the switch, not the loop, so the loop body increments c for every i except 2, which gives 4.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int c = 0; for (int i = 0; i < 5; i++) { switch (i) { case 1: continue; } c++; }…
- What is printed? c #include <stdio.h> int main(void) { int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d", ((m + 1) + 2)); }
- What is printed? c #include <stdio.h> int f(void) { static int a[3]; a[0]++; return a[0]; } int main(void) { int x = f(); int y = f(); int…
- What is printed? Assume short is 2 bytes with 2-byte alignment and char is 1 byte. c #include <stdio.h> struct S { short a; char b; }; int…
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t a = 5, b = 10; uint8t d = a…
- Seven people stand in a circle and every third person is removed until one is left. The recursion J(n, k) gives the 1-based survivor…