Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

3. Describe the products and services MFIs provide.

Answered: 1 week ago

Question

=+ 4. Why should policymakers think about incentives?

Answered: 1 week ago

Question

=+ 2. What is the opportunity cost of seeing a movie?

Answered: 1 week ago