I'm trying to write a function that takes two pointers as arguments and then makes the first pointer point to the object the second pointer was pointing to and the second to the object pointed to by the first.
void swap(int *x, int *y)
{
int *s;
s = x;
x = y;
y = s;
}
In the main function, I'll do something like
int x, y;
swap(&x, &y);
std::cout << &x << " " << &y << std::endl;
But it seems like the addresses don't change.
If instead I dereference the pointers and try to change the values, the values are swapped as expected. I'm wondering why this function won't change where the pointers point to.