The GATE Grind

GATE 2009 CS – Question 18

Programming and Data Structures · Recursion · 1 mark · Multiple choice

Consider the program below. What value is printed?

#include <stdio.h>
int fun(int n, int *f_p) {
  int t, f;
  if (n <= 1) { *f_p = 1; return 1; }
  t = fun(n-1, f_p);
  f = t + *f_p;
  *f_p = t;
  return f;
}
int main() {
  int x = 15;
  printf("%d\n", fun(5, &x));
  return 0;
}
  1. 6
  2. 8
  3. 14
  4. 15

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 8

Explanation

We are sorry we couldn't write detailed soluition for this, we are working on it!, please consider asking your own AI, its just 2-3 clicks with very minimum effort

More Recursion questions

All Recursion questions →