Programme of swaping | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Programme of swaping

can anyone help me in a programme of swap

17th Oct 2016, 7:12 AM
Sakshi bissa
1 Answer
+ 2
The swap function, a classic to show the usefulness of passing variables by reference. void swap(int &a, int &b) { int tmp = a; a = b; b = tmp; } Alternative version, without tmp: void swap2(int &a, int &b) { a = a + b; b = a - b; a = a - b; }
17th Oct 2016, 8:38 AM
Zen
Zen - avatar