ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int calls = 0;
int A(int m, int n) {
    calls++;
    if (m == 0) return n + 1;
    if (n == 0) return A(m - 1, 1);
    return A(m - 1, A(m, n - 1));
}
int main(void) {
    int v = A(1, 3);
    printf("%d %d", v, calls);
}
  1. A. 5 9
  2. B. 5 7
  3. C. 4 8
  4. D. 5 8

Correct answer: D. 5 8

A(1, n) = n + 2, so A(1, 3) = 5. The recursion makes eight calls in total, counting the base case calls at m = 0.

More C Programming questions

Exams that ask this topic