← 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;
}
- A.28
- B.16
- C.12
- 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 →