is it possible to swap the value of two variables without using a third variable

1 reply [Last post]
VishalSharan
Offline
Last seen: 7 years 10 weeks ago
Joined: 2011-12-25
bOt Points: 54

please tell me how can I swap the values of two variables without using a third variable

abazovic
Offline
Last seen: 7 years 11 weeks ago
Joined: 2012-07-03
bOt Points: 54
By using + and -

int a =5;

int b= 7;

a=a+b;//lose a now  a=5+7 = 12 b=7

b=a-b;//in b set value that was in a a=12 and b=12-7=5 nov 

 a=a-b;//in a set value from b in a=12-5=7 b=7   (now is a=7 b=5 at strat it was a=5 and b=7)