2 Recursion
2 Recursion
else
return 0;
2. What is the return value of the function foo when it is called as foo(345, 10) ?
a) 345 b) 12 c) 5 d) 3
3. What is the return value of the function foo when it is called as foo(513, 2)?
a) 9 b) 8 c) 5 d) 2
5. Consider the C functions foo and bar given below: (GATE 2017)
int foo(intval)
{
int x=0;
while(val> 0)
{
x = x + foo(val--);
}
returnval;
}
int bar(intval)
{
int x = 0;
while(val> 0)
{
x= x + bar(val-1);
}
returnval;
}
Invocations of $foo(3)$ and $bar(3)$ will result in:
A) Return of 6 and 6 respectively.
B) Infinite loop and abnormal termination respectively.
C) Abnormal termination and infinite loop respectively.
D) Both terminating abnormally.