Simple swap function…why doesn’t this one swap?

You’re missing *s in the swap function. Try:

void swap(int* a, int* b)
{
 int temp = *a;
 *a = *b;
 *b = temp;
}

That way, instead of just swapping the pointers, you’re swapping the ints that the pointers are pointing to.

Leave a Comment