previous | index | next

More on Argument Passing

Suppose we want a swap function that works so that the following code:

int p = 1;
int q = 2;
    
cout << "p = " << p << "  q = " << q << endl;
swap(p, q);
cout << "p = " << p << "  q = " << q << endl;

produces the following output:

p = 1  q = 2
p = 2  q = 1

previous | index | next