ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int main(void) {
int x = 2;
switch (x) {
case 1:
case 2:
case 3:
printf("low ");
break;
case 4:
case 5:
printf("high ");
break;
default:
printf("other ");
}
}- A. low
- B. high
- C. other
- D. low high
Correct answer: A. low
Grouped cases 1, 2, 3 (stacked with no code between them, just falling through to the shared body) all lead to the same "low " print; x=2 matches case 2, falling into "low ", then break exits the switch.
More C Programming questions
- What is printed? c int main(void) { int arr[5] = {1, 2, 3, 4, 5}; int sum = 0; for (int i = 0; i < 5; i += 2) { sum += arr[i]; }…
- What is printed? c int fact(int n); int main(void) { printf("%d", fact(5)); } int fact(int n) { return n <= 1 ? 1 : n fact(n - 1); }
- What is printed? c int x = 1; void incrementGlobal(void) { x++; } int main(void) { int x = 10; incrementGlobal(); printf("%d", x); }
- What is printed? c int f(void) { static int x = 10; x += 5; return x; } int main(void) { int a = f(); int b = f(); int c = a + b…
- What happens when these two files are linked together? c / file1.c / extern int shared; void show(void) { printf("%d", shared); } /…
- What is printed? c void f(void) { static int calls = 0; int local = 0; calls++; local++; printf("%d %d ", calls, local); } int main(void)…