🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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;
}
  1. A.321321
  2. B.123321
  3. C.321123
  4. 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 →