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

#include <iostream> using namespace std; void figureMeOut( int& x, int y, int& z

ID: 3543757 • Letter: #

Question

#include <iostream>
using namespace std;

void figureMeOut( int& x, int y, int& z);
int main( )
{
int a, b, c;
a = 10;
b = 20;
c = 30;
figureMeOut(a, b, c);
cout << a << " " << b << " " << c << endl;
return 0;
}
void figureMeOut( int& x, int y, int& z)
{
cout << x << " " << y << " " << z << endl;
x = 1;
y = 2;
z = 3;

}

output is 10 20 30

                 1  2  3

                 1 20 3

why this output?   

Explanation / Answer

OUTPUT is
10 20 30
1 20 3

x and z are passed as pass by reference where those values can be modifed inside function and it will be reflected back to calling function.
while y is passed as pass by value where value can be modified inside function but change will not be reflected back to calling function.
that is the reason x and y values got changed to 1 and 3 respectively.
while y value still stayed at 20.