One line swap of integers source code
This snippet submitted by abhilash on 2006-08-05. It has been viewed 1557 times.
Rating of 7.5 with 22 votes
#include <stdio.h>
int main()
{
int a=10,b=20;
printf("A:%d B:%d\n",a,b);
a=(a+b)-(b=a); //SWAPS
printf("A:%d B:%d\n",a,b);
return 1;
}
More C and C++ source code snippets
Add a snippet!