ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
int x = 5, s = 0;
switch (x) {
default: s += 1;
case 1: s += 10;
case 2: s += 100; break;
case 3: s += 1000;
}
printf("%d", s);- A. 1111
- B. 1
- C. 101
- D. 111
Correct answer: D. 111
No case matches 5, so control jumps to default, wherever it is written. With no break it falls through case 1 and case 2 (1 + 10 + 100) and stops at that break. '1' assumes default ends the switch; '1111' ignores the break.
More C Programming questions
- What is f in the declaration below? c int ((f)(int))[3];
- What is printed? c char s[10] = "abc"; char t[] = "xyz"; strncat(s, t, 2); printf("%s %zu %d", s, strlen(s), strncmp(s, "abcx", 4) == 0);
- What is printed? c char s[] = {"alpha", "beta", "gamma", "delta"}; char p = s; p += 2; printf("%c ", p); printf("%c ", ((p - 1) + 2))…
- What is printed? c int c = 0; int g(int n) { c++; if (n <= 2) return 1; return g(n - 1) + g(n - 2) + g(n - 3); } int main(void) { int r =…
- Assume 32-bit unsigned int. What is printed? c unsigned f(unsigned x) { return (x & 0x55555555u) << 1 | (x >> 1) & 0x55555555u; }…
- What is printed? c #define X 3 #define Y X 2 #if Y == 6 #define Z 1 #else #define Z 2 #endif printf("%d %d", Z, Y + 1 2);