The function swap fails to
swap the values of the actual parameters because
x and
y are value parameters.
The invocation swap(a, b) results in the values
of the actual
parameters a and b
being copied into the formal parameters
x and y, respectively.
Then, within the body of
swap, the values of
x and y are interchanged,
and the function terminates. Upon termination, the new values of
x and y are not copied
back into the actual parameters. Consequently, the values of
the actual parameters are unaffected by the function.
To get the function to work properly we should change the header to
void swap(int& x, int& y);