S
Steve
How do you rewrite the swap function without using a tmp variable in
the swap function????
int main()
{
int x = 3;
int y = 5;
// Passing by reference
cout << "Passed by reference, before" << endl;
cout << "x = " << x << " y = " << y << endl;
swap(x,y);
cout << "Passed by reference, after" << endl;
cout << "x = " << x << " y = " << y << endl;
return 0;
}
void swap(int &x, int &y)
{
int tmp;
tmp = x;
x = y;
y = tmp;
}
the swap function????
int main()
{
int x = 3;
int y = 5;
// Passing by reference
cout << "Passed by reference, before" << endl;
cout << "x = " << x << " y = " << y << endl;
swap(x,y);
cout << "Passed by reference, after" << endl;
cout << "x = " << x << " y = " << y << endl;
return 0;
}
void swap(int &x, int &y)
{
int tmp;
tmp = x;
x = y;
y = tmp;
}