ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
void p(const char *s) {
if (!*s) return;
putchar(*s);
p(s + 2);
putchar(*s);
}
int main(void) { p("abcdef"); }- A. aceca
- B. ace
- C. acefeca
- D. aceeca
Correct answer: D. aceeca
Each call prints its character, recurses two characters further, then prints the same character again on the way back. Calls visit 'a', 'c', 'e'; from 'e' (index 4) s + 2 is index 6, the '\0', so the recursion stops there. Output: a c e on the way down, e c a on the way up → "aceeca". The step of 2 stays inside the 7-byte array, so it is well defined.
More C Programming questions
- What is printed? c / LP64: 4-byte int, 8-byte pointers / int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = a; printf("%d %d %zu %zu"…
- What is printed? c int i, c = 0; for (i = 0; i < 6; i++) if (i % 2 == 0 || ++c > 1) c += 10; printf("%d %d", i, c);
- What is printed? c / 16-bit unsigned short, 32-bit int and unsigned / unsigned short a = 3, b = 5; printf("%d %u %d", a - b, 3u - 5u…
- What is printed? c #define ABS(x) x < 0 ? -x : x printf("%d %d", ABS(2 - 5), ABS(-4) 2);
- What is printed? c const char s = "mississippi"; printf("%td %td %td", strchr(s, 's') - s, strrchr(s, 's') - s, strstr(s, "ssip") - s);
- What is printed? c / 4-byte int / struct V { int a[3]; }; void f(struct V v) { v.a[0] = 9; } void g(int a[3]) { a[0] = 9; } int main(void)…