GATE 2013 CS (CS1) – Question 52
p starts at five. Find f(p,p). The first parameter is passed by reference and the second by value.
int f(int &x, int c) {
c=c-1;
if (c==0) return 1;
x=x+1;
return f(x,c)*x;
}Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: MTA
Explanation
The final key awards marks to all. The recursive calls share x and increment it four times, ultimately to nine. Reading the multiplier x after recursive evaluation would give 9⁴=6561. Reading each frame’s x before descending gives 6×7×8×9=3024. The language/evaluation-order assumptions are not sufficiently specified, so a unique numeric answer is not imposed.