# GATE | GATE CS 2020 | Question 56

Consider the following C functions.

 `int` `fun1(``int` `n) { ` `    ``static` `int` `i= 0; ` `    ``if` `(n > 0) { ` `       ``++i; ` `      ``fun1(n-1); ` `   ``} ` `  ``return` `(i); ` `} ` `int` `fun2(``int` `n) { ` `   ``static` `int` `i= 0; ` `   ``if` `(n>0) { ` `      ``i = i+ fun1 (n) ; ` `      ``fun2(n-1) ; ` `  ``} ` `return` `(i); ` `} `

The return value of fun2(5) is ________ .

Note – This question was Numerical Type.
(A) 55
(B) 45
(C) 50
(D) 52

Explanation: fun1() adds its previous value because of ‘static variable‘.
Therefore, it prints 55.

 `#include   ` ` `  `int` `fun1(``int` `n); ` `int` `fun2(``int` `n); ` ` `  `int` `fun1(``int` `n) { ` `    ``static` `int` `i= 0; ` `    ``if` `(n > 0) { ` `       ``++i; ` `      ``fun1(n-1); ` `   ``} ` `  ``return` `(i); ` `} ` `int` `fun2(``int` `n) { ` `   ``static` `int` `i= 0; ` `   ``if` `(n>0) { ` `      ``i = i+ fun1 (n) ; ` `      ``fun2(n-1) ; ` `  ``} ` `return` `(i); ` `} ` ` `  `int` `main()  ` ` ``{  ` `    `  `  ``printf``(``"%d"``, fun2(5));  ` `  ``return` `0;  ` ` ``}  `

Option (A) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

1

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.