Consider the following C function : int f(int n) { static int i = 1; if (n >= 5) return n; n = n + i; i++; return f(n); } The value returned by f(1) is
- A. 5
- B. 6
- C. 7
- D. 8
Answer: C. 7
Explanation: f(1): i=1, n=1+1=2, i=2, call f(2). f(2): i=2, n=2+2=4, i=3, call f(4). f(4): i=3, n=4+3=7, i=4, call f(7). f(7): n>=5, return 7.