0

Is there is any way to reverse the value of x,y variables with out using new z variable ???

C++ https://code.sololearn.com/c52UV7eX5VS9/?ref=app

16th Nov 2017, 10:40 AM
Elia Garas
3 Respostas
+ 5
x ^= y; y ^= x; x ^= y; or x += y y = x - y x -= y
16th Nov 2017, 11:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
thank's alot 😎😎
16th Nov 2017, 1:44 PM
Elia Garas
0
Yes, but it still requires storing x in a temporary. #include<iostream> using namespace std; int x=10,y=20; void swap(int z) { x=y; y=z; } int main(){ swap(x); cout<<"x="<<x<<endl<<"y="<<y; return 0; }
16th Nov 2017, 11:49 AM
John Wells
John Wells - avatar