0

Write a programs in c++ that exchange data using swap function to interchange the given two number

passing by refference

29th Jul 2017, 4:47 AM
PIYUSH CHITATWAR
2 Answers
+ 6
void swap(int& a, int& b) { a = a+b; b = a-b; a = a-b; }
29th Jul 2017, 4:54 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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; }
29th Jul 2017, 5:47 AM
Slak
Slak - avatar