🎙 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 4 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int g(int n) {
    if (n <= 0) return 0;
    return n + g(n - 2);
}
int main(void) {
    printf("%d", g(7));
    return 0;
}
  1. A.28
  2. B.16
  3. C.12
  4. D.7
Answer & explanation

Correct answer: 16

7 + 5 + 3 + 1 + g(-1) = 16 + 0 = 16.

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 →