Your comment is correct. Use *.
But you need to pass arguments like:
Code:
int a, b;
a = 8;
b = 5;
swap(&a, &b);
You could do yourself a favor and implement this, wich is much neater:
Code:
void swap(int &a1, int &a2)
{
if(a1 > a2)
{
int temp;
temp = a1;
a1 = a2;
a2 = temp;
}
}
int main(int argc, char* argv[])
{
int a, b;
a = 8;
b = 5;
swap(a, b);
cout<<"a: "<<a<<" b: "<<b<<endl;
return 0;
} You could do yourself even another favor: not calling your functions "swap".
Why? Because swap is already defined in the
namespace std;
Check this complete code out:
Code:
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
int a, b;
a = 8;
b = 5;
swap(a, b);
cout<<"a: "<<a<<" b: "<<b<<endl;
return 0;
} Better rename your functions to something everyone understands in the given situation in general.