Question
Show the Activation Records (ARs) and output for the following program execution. [1] int ack(int m, int n) { if (m == 0){ return n
Show the Activation Records (ARs) and output for the following program execution.
[1]
int ack(int m, int n)
{
if (m == 0){
return n + 2;
}
else if((m > 0) && (n == 0)){
return ack(m - 1, 1);
}
else if((m > 0) && (n > 0)){
return ack(m - 1, ack(m, n - 1));
}
}
int main()
{
int ans;
ans = ack(1, 3);
cout << a << endl;
return 0;
}
[2] Show the Activation Records (ARs) and output for the following program execution.
int mgcd(int a, int b) {
if (a == 0 || b == 0)
return 0;
else if (a == b)
return a;
else if (a > b)
return mgcd(a-b, b+1);
else
return mgcd(a, b-a);
}
int main() {
int a = 63, b = 42;
cout<<"MGCD of "<< a <<" and "<< b <<" is "<< mgcd(a, b);
return 0;
}=====================================
[3] Given the following code segments:
fun( a, b){
a += b + 2;
b += b * 2;
}int main (){
int x = 4;
int y = 3;fun(x,y);
fun(x,y);
print x, y;
}(A) What will be the ouput if the actual parameters were passed by value?
(B) What will be the output if the actual parameters were passed by reference?
(C) What will be the output if x,y were passed by value and y passed by result?
(D) What will be the output if x was passed by value and y passed by value-result?
Step by Step Solution
3.46 Rating (143 Votes )
There are 3 Steps involved in it
Step: 1
1 Activation Records ARs and output for the following pr...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started