ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int s = 0;
for (int i = 0; i < 5; i++) {
switch (i) {
case 1: continue;
case 3: break;
default: s += 10;
}
s += i;
}
printf("%d", s);- A. 30
- B. 40
- C. 36
- D. 39
Correct answer: D. 39
Inside a switch, break leaves only the switch, but continue goes to the next loop iteration. i = 1 skips everything; i = 3 skips the +10 but still adds 3. Total: (10 + 0) + (10 + 2) + 3 + (10 + 4) = 39.
More C Programming questions
- What is printed? c int a[] = {10, 20, 30}; printf("%d", a[1, 2]);
- What is printed? c struct P { int x; int y; } p = {7, 9}; int q = (int )&p; printf("%d", q);
- What is printed? c int p(int n, int m) { / ways to write n as a sum of parts <= m / if (n == 0) return 1; if (n < 0 || m == 0) return 0…
- What is printed? c printf("%#x %#o %x", 255, 8, -1 & 0xFF);
- Assume 8-bit unsigned char. What is printed? c printf("%d %d %d", (int)-3.7, (unsigned char)-1, (int)(0.1 30));
- What is printed? c int ways(int amt, int k) { static const int c[] = {1, 2, 5}; if (amt == 0) return 1; if (amt < 0 || k == 0) return 0…