I would like to know how can the swapping function be implemented using pointers, void swap (int*, int*)
//function prototypes
void swap(int& a, int& b);
//function (passing by ref)
void swap(int& a, int& b)
{
int t = a;
a = b;
b = t;
}
Is this correct?
//Using pointers
void swap(int *num1, int *num2)
{
int tempvar1;
tempvar1 = *num1;
*num1 = *num2;
*num2 = tempvar1;