ProgrammingVery hardGATE CS
What is the exact output?
What is the exact output?
#include <stdio.h>
void p(int n) {
if (n <= 0) return;
printf("%d", n);
p(n - 1);
printf("%d", n);
p(n - 2);
}
int main(void) {
p(4);
return 0;
}- A. 43211231142112
- B. 43211234112112
- C. 4321123112
- D. 43211231142121
Correct answer: A. 43211231142112
Tracing p(4): prints 4, p(3) prints 3, p(2) prints 2, p(1) prints 1, returns through p(0), prints 1, p(-1) returns; back in p(2) prints 2, then p(0); in p(3) prints 3 and calls p(1) which prints 11; in p(4) prints 4 and calls p(2) which prints 2112, giving 43211231142112.
More C Programming questions
- What is printed? Assume int is 4 bytes and the array is a 2-D array object of automatic storage. c #include <stdio.h> int main(void) { int…
- What is printed? Assume IEEE-754 float (32-bit) and double (64-bit) with no extended-precision evaluation. c #include <stdio.h> int…
- What is printed? c int a[5] = {1, 2}; printf("%d %d %zu", a[1], a[2], sizeof a / sizeof a[0]);
- What is printed? c printf("%.1f %d", 7 / 2 2.0, (int)(7 / 2.0 2));
- What is printed? c printf("%d %d", 6 & 3 << 1, ~5 + 1);
- What is printed? c int n = 2, s = 0; switch (n) { case 1: s += 1; case 2: s += 2; case 3: s += 3; break; default: s += 9; } printf("%d", s);