Swap in is often used in books on C++ because it's an excellent example of why references are useful. Sometimes you need a function to change two variables, but a function can only return one value. For example:

void swap(int i, int j)
{

int hold = i;
i = j;
j = hold;
}

If you use this function, you'll find that the values of i and j afterwards have remained the same. However, if you pass i and j by reference:

void swap(int &i, int &j)
{

int hold = i;
i = j;
j = hold;
}

Because the actual address of the variable was passed to the function, not just its value, the variable will remain changed after the function completes.

Swap still hasn't finished its usefulness however. It also works as a great example of templates, since its a very small piece of code. A much less complicated example of templates than say the quicksort algorithm:

template<class T>
void swap(T &i, T &j)
{

T hold = i;
i = j;
j = hold;
}

Now you have a function that can swap any type of variable, without having to overload the function for every data type. However, for classes and structures you'll still have to through function template specialization, or by overloading the operators for that class or structure. (overloading the equal operator is preferable)