0
Is there is any way to reverse the value of x,y variables with out using new z variable ???
3 Réponses
+ 5
x ^= y;
y ^= x;
x ^= y;
or
x += y
y = x - y
x -= y
+ 2
thank's alot 😎😎
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;
}