Confusion about pointers and references in C++

In the first example, std::swap is called, because of your using namespace std.
The second example is exactly the same as the first one, so you might have no using.

Anyway, if you rename your function to my_swap or something like that (and change every occurence), then the first code shouldn’t work, as expected. Or, remove the using namespace std and call std::cin and std::cout explicitly. I would recommend the second option.

Leave a Comment