+ 1
How can we switch two variables values using only two variables..?
3 Respuestas
+ 1
It's a data manipulation trick, there is more than one way.
For integers:
Use 1 variable to hold difference.
Then use difference to swap the other over variable.
Then use the value and difference get the other value back.
+ 1
how ?
+ 1
y = y - x; //y holds the difference
x = x + y; //x holds the y value
y = x - y; //y holds the x value;