ProgrammingHardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
long long f(int n) {
    return n == 0 ? 1 : 2 * f(n - 1) + 1;
}
int main(void) {
    printf("%lld", f(10));
}
  1. A. 1023
  2. B. 2048
  3. C. 2049
  4. D. 2047

Correct answer: D. 2047

f(n) = 2 f(n - 1) + 1 with f(0) = 1 gives 2^(n+1) - 1, so f(10) = 2047.

More C Programming questions

Exams that ask this topic