GATE 2014 CS (CS2) – Question 52
Consider the C function:
int f(int j) {
static int i = 50;
int k;
if (i == j) {
printf("something");
k = f(i);
return 0;
} else return 0;
}
Which is TRUE?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (D) Exhausts the runtime stack or loops infinitely for j = 50
Explanation
Static i is initialised once to50 and is never changed. For j=50 the condition stays true in every recursive call f(i), repeatedly printing and recursing without reaching a return. Thus **D**, stack exhaustion or infinite recursion occurs. Other jvalues return0 immediately.