← Quiz: Recursion and Stack Frames: all 10 questions
Quiz: Recursion and Stack Frames · Question 8 of 10
What does this print? (code)
What does this print?
#include <stdio.h>
void p(int n) {
if (n == 0) return;
printf("%d", n);
p(n - 1);
printf("%d", n);
}
int main(void) {
p(3);
return 0;
}
- A.321321
- B.123321
- C.321123
- D.333111
Answer & explanation
Correct answer: 321123
The first printf runs while winding (3 2 1), the second while unwinding (1 2 3).
Can you get the rest right without peeking?
Take the timed Quiz: Recursion and Stack Frames quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →