C++: Swap function

Revision en1, by Madiyar, 2015-09-05 02:58:34

Small brainteaser. Do you know that function below doesn't work in some cases.
Try to attack it.

#include <iostream>

using namespace std;

void swap(int &a, int &b){ 
	a = a + b; 
	b = a - b; 
	a = a - b;
}
Tags swap, c++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Madiyar 2015-09-05 02:58:34 259 Initial revision (published)