Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Show the output of the following codes if: call by value is used call by value-r

ID: 3606108 • Letter: S

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 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

Explanation / Answer

5 7
3 2
6 9
3 2

call by value-result:
5 7
5 7
10 15
15 7

call by reference:
5 7
5 7
20 20
20 7

call by value
3 5 8
1 2
4 6 10
1 2

call by value-result:
3 5 8
5 8
16 24 40
16 40

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote