Sunday, May 17, 2015

Swap 2 numeric variables without introducing another variable

int a = 4;
int b = 5;
a = a + b; // a = 9
b = a - b; // b = 4
a = a - b; // a = 5

No comments:

Post a Comment