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

Given the following function definition: void shift(int& x, int& y) { y = x; x =

ID: 3574782 • Letter: G

Question

Given the following function definition:


void shift(int& x, int& y)
{
y = x;
x = y;
}


What is output after the following code is executed?
int first = 5, second = 8;
shift(first, second);
cout << first << " " << second << endl;

8 8

5 5

5 8

8 5

Given the following function definition:


void shift(int& x, int& y)
{
y = x;
x = y;
}


What is output after the following code is executed?
int first = 5, second = 8;
shift(first, second);
cout << first << " " << second << endl;

Answers:

8 8

5 5

5 8

8 5

Explanation / Answer

Answer: 5 5

int variable first value is 5

int variable second value is 8

we are passing their address to shift function

in shift function, y = x; we assigned x value to y so x value is 5 and y value 5 now

in second line of that function, x = y; we assigned y value to x. since y value is 5 x value is also 5

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