Question 1
5 marksTrace sum_down(3) using the code above. Give the calls in order and the value returned by each call as the stack unwinds.
Show solution and marking guidance
Indicative answer:
- Calls:
sum_down(3), sum_down(2), sum_down(1), sum_down(0), in that order (1). - The base call returns 0 (1).
- The calls at 1, 2 and 3 return 1, 3 and 6 respectively (1 each).
The final printed value is 6; this is the last return already credited.