← Quiz: Recursion and Stack Frames: all 10 questions
Quiz: Recursion and Stack Frames · Question 1 of 10
What does this print? (code)
What does this print?
#include <stdio.h>
void f(int n) {
if (n == 0) return;
f(n - 1);
printf("%d ", n);
}
int main(void) {
f(4);
return 0;
}
- A.4 3 2 1
- B.1 2 3 4
- C.4 3 2 1 0
- D.0 1 2 3 4
Answer & explanation
Correct answer: 1 2 3 4
The printf comes after the recursive call, so it runs while unwinding: the deepest call (n = 1) prints first.
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 →