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;
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.