0
Write a programs in c++ that exchange data using swap function to interchange the given two number
passing by refference
2 Antworten
+ 6
void swap(int& a, int& b)
{
a = a+b;
b = a-b;
a = a-b;
}
+ 2
I'm just curious, would it not be better to use a temporary varible?
To prevent the int from overflowing
void swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}