🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: C Functions and Recursion: all 10 questions

Quiz: C Functions and Recursion · Question 2 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int f(int n) {
    if (n == 0) return 0;
    return n + f(n - 1);
}
int main(void) {
    printf("%d", f(5));
    return 0;
}
  1. A.5
  2. B.15
  3. C.120
  4. D.10
Answer & explanation

Correct answer: 15

f(5) = 5 + 4 + 3 + 2 + 1 + 0 = 15.

Can you get the rest right without peeking?

Take the timed Quiz: C Functions and Recursion quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →