ProgrammingHardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int f(int n) {
    return n <= 1 ? 0 : 1 + f(n / 2);
}
int main(void) {
    printf("%d", f(10));
}
  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

f(10) = 1 + f(5) = 2 + f(2) = 3 + f(1) = 3, so the recursion depth is 3.

More C Programming questions

Exams that ask this topic