ProgrammingVery hardTCS NQT · Infosys
int r = 0; switch (2) { case 1: r += 1; case 2: r += 10; case 3: r += 100; break; default: r += 1000; } What is r?
- A. 10
- B. 110
- C. 100
- D. 1110
Correct answer: B. 110
Case 2 matches and adds 10, then control falls through to case 3, which adds 100, and the break stops the switch. The total is 110.
More C Programming questions
- for (int i = 0, j = 10; i < j; i += 3, j -= 3) count++; How many times does the body run?
- int n = 5; int r = n++ 2; What are the final values of r and n?
- Adding two non-negative ints a and b without +, a loop repeats a = a ^ b and b = (old a & old b) << 1 until b is 0. Starting with a = 5…
- uint8t sum = (uint8t)(200 + 100); if (sum < 50) printf("yes"); else printf("no"); What is printed?
- char msg[] = "abc"; printf("%c", msg[msg[0] - 'a' + 1]); What is printed?
- for (int i = 0; i < 10; i++) for (int j = 1; j < 10; j = 2) count++; How many times does count increase?