Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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 ?
    1. The function returns 0 for all values of j.
    2. The function prints the string something for all values of j.
    3. The function returns 0 when j = 50.
    4. The function will exhaust the runtime stack or run into an infinite loop when j = 50.
Correct Option: D

When j = 50, j (50), the function goes to an infinite loop by calling f(i) recursively for i = j = 50



Your comments will be displayed only after manual approval.