-
Consider the following C function :
int f (int n)
{ static int i = 1;
if (n > = 5) return n;
n = n + 1;
i ++;
return f(n);
}
The value returned by f (1) is
-
- 5
- 6
- 7
- 8
- 5
Correct Option: C
The iterations that the given code will undergo are: From the given conditions we does not take into account when n = 1
Iteration 1
N = 1 + 1 = 2 therefore, i = 2
Iteration 2
N = 2 + 2 = 4 therefore, i = 3
Iteration 3
N = 4 + 3 = 2 = 4 therefore, i = 4
Hence, the value returned after three iterations is 7
When, i = 4 and it also fulfill the condition of n>=5