Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ CODE: #include using namespace std; void swap (int x, int y) { int hold ; hold = x ; x = y ; y

C++ CODE:

#include

using namespace std;

void swap (int x, int y)

{

int hold ;

hold = x ;

x = y ;

y = hold ;

cout << At end of swap method x is << x << endl;

cout << At end of swap method y is << y << endl;

}

int main ()

{

int a = 10, b= 20;

cout << a is << a << endl;

cout << b is << b << endl;

swap (a,b);

cout << In main after swap a is << a << endl;

cout << In main after swap b is << b << endl;

}

OUTPUT:

a is 10

b is 20

At end of swap method x is 20

At end of swap method y is 10

In main after swap a is 10

In main after swap b is 20

Program ended with exit code: 0

1)How can you fix the function to also swap a and b in main?

2)Explain how pass-by-value works

3)Explain how pass-by-reference works

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Describe alternatives to recruitment.

Answered: 1 week ago