Possible Duplicate:
difference between a pointer and reference parameter?
Using C++ i'm wondering what's the difference in the use of & and * in parameters?
For example:
void swap(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
That apparently would swap the integers a and b. But wouldn't the following function do exactly the same?
void swap(int *a, int *b)
{
int temp = *b;
*b = *a;
*a = temp;
}
I was just wondering when it is appropriate to use each one, and perhaps the advantages of each one.