1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
using namespace std;
void surprise(int z, int x, int y);
int main()
{
int x = 1, y = 2, z = 3;
std::cout << "\nSending \"x\" as " << x << " \"y\" as " << y << " and \"z\" as " << z << std::endl;
surprise(x, y, z); // Sending 1, 2, 3
cout << "in main: x=" << x << " y=" << y << " z=" << z << endl;
std::cout << "\nSending \"z\" as " << z << " \"z\" as " << z << " and \"x\" as " << x << std::endl;
surprise(z, z, x); // Sending 3, 3, 1
cout << "in main x=" << x << " y=" << y << " z=" << z << endl;
return 0;
}
// Second time through receiving 3, 3, 1
void surprise(int z, int x, int y)
{
z++;
x = z * y;
y = x - 1;
cout << "in function: x=" << x << " y=" << y << " z=" << z << endl;
}
|