ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int c = 0;
switch (3) {
default: c += 1;
case 1: c += 10;
}
printf("%d", c);
}- A. 10
- B. 11
- C. 1
- D. 0
Correct answer: B. 11
No case matches 3, so control goes to default, which falls through into case 1. Both additions run, giving 11.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 1 ? 2 : 3 ? 4 : 5); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (1, 2)); }
- What is printed? c #include <stdio.h> int main(void) { char c = 'a'; printf("%d", c++ == 'a' && c == 'b'); }
- What is printed? c #include <stdio.h> int main(void) { printf("%s", "ab" "cd"); }
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { printf("%u", 1 ? -1 : 0u); }
- How many partitions of 6 into distinct parts are there? The recursion below counts them. What is printed? c #include <stdio.h> int dp(int…