Question: 1. (a) Consider the following recursive function: int p(int m, int n) { int result; if (n = 1) { result = m; }
1. (a) Consider the following recursive function: int p(int m, int n) { int result; if (n = 1) { result = m; } else { result mp(m, n- = - 1); } } i. 11. return result; Considering recursion, what is the purpose of the if part? What is the purpose of the else part? Explain the purpose of this p function (provide an example with actual numbers assigned to m and n with the initial call of p. (b) This is how C++ manages recursion: each time a recursive call to a function is made, all the arguments and local variables for that version of the call are saved in memory. This means at any point there are as many copies of the function's arguments and variables as there are recursive calls. After the final call is completed, the saved information is unwound. What is the effect of the way that C++ manages recursion on a statement written before the if statement? What is the effect on a statement written after the if statement?
Step by Step Solution
3.23 Rating (141 Votes )
There are 3 Steps involved in it
The purpose of the if part in the recursive function pint m int n is to define the ba... View full answer
Get step-by-step solutions from verified subject matter experts
