One line swap of integers source code
This snippet submitted by abhilash on 2006-08-05. It has been viewed 4764 times.
Rating of 8.1 with 67 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!