How to swap 2 values using only 2 variables..?? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

How to swap 2 values using only 2 variables..??

Not using any temporary variable

24th Jan 2018, 4:52 PM
DAVE
DAVE - avatar
2 Réponses
+ 3
This is a well known trick. But you need to be careful when a+b is overflowing the corresponding data type. a = a+b; b = a-b; a = a-b;
24th Jan 2018, 5:05 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 22
//so many same question already exist , u can search before posting a question //might be marked as [duplicate] soon https://www.sololearn.com/Discuss/245511/?ref=app https://www.sololearn.com/Discuss/564903/?ref=app https://www.sololearn.com/Discuss/811929/?ref=app
24th Jan 2018, 5:06 PM
Gaurav Agrawal
Gaurav Agrawal - avatar