Pointers in swap values
I would like to know how can the swapping function be implemented using pointers, void swap (int*, int*)
1 2 3 4 5 6 7 8 9 10
|
//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?
1 2 3 4 5 6 7 8 9
|
//Using pointers
void swap(int *num1, int *num2)
{
int tempvar1;
tempvar1 = *num1;
*num1 = *num2;
*num2 = tempvar1;
|
Yes.
Thanks!
Topic archived. No new replies allowed.