29 votes

Consider the C function given below.

int f(int j) { static int i = 50; int k; if (i == j) { printf("something"); k = f(i); return 0; } else return 0; }

Which one of the following is **TRUE**?

- The function returns $0$ for all values of $j$.
- The function prints the string
**something**for all values of $j$. - The function returns $0$ when $j = 50$.
- The function will exhaust the runtime stack or run into an infinite loop when $j = 50$.

37 votes

Best answer

0

@rajatmyname because option a is strictly talking about all value of j but for 50 it will trapped in a loop

0

I have a small doubt.

In option D, it is clearly given that :

**The function will exhaust the runtime stack or run into an infinite loop when j=50.**

Consider only the underlined part. How at j=50, program will run into an infinite loop?

9 votes

1. int f(int j) { 2. static int i = 50; 3. int k; 4. if (i == j) { 5. printf("something"); 6. k = f(i); key line function loop from 6 to 1 always when j=50 even not return 0. so 1st and 3rd statement are false. return 0; } else return 0; }

since for value other then 50 it will not print anythng b/c not satisfy if property.

so ans is D. since always same value pass as value.