Question
Show the output of the following codes if: call by value is used call by value-result is used call by reference is used proc (int
Show the output of the following codes if:
call by value is used
call by value-result is used
call by reference is used
proc (int x, int y) {
x=x+y;
y=x+y;
cout << x << " " << y << endl;
}
main () {
int y = 2, x = 3;
proc (x, y);
cout << x << " " << y << endl;
proc (x, x);
cout << x << " " << y << endl;
}
void proc (int x, int y, int z) {
x=y+z;
y=x+z;
z=x+y;
cout << x << " " << y << " " << z << endl;
}
int main () {
int a = 1, b = 2;
proc (a, a, b);
cout << a << " " << b << endl;
proc (a, b, b);
cout << a << " " << b << endl;
}
Give the output and trace the call stack for the following 2 programs
1.
void Uno (int x) {
cout << "Uno B " << x << endl;
if (x > 0)
Uno(x-1);
cout << "Uno E " << x << endl;
}
void Dos (int x) {
cout << "Dos B " << x << endl;
Uno(x-1);
cout << "Dos E " << x << endl;
}
int main(){
Dos (2);
Dos (3);
cout << "l8r" << endl;
return 0;
}
2.
void Bubba (int x) {
cout << "B " << x << endl;
if (x > 0) {
Bubba(x-2);
cout << "M " << x << endl;
Bubba(x-1);
}
cout << "E " << x << endl;
}
int main(){
Bubba(2);
cout << "l8r" << endl;
return 0;
}
There are related question so I would appreciate if you answer them both.
Thanks in advance
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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