One line swap of integers source code

This snippet submitted by abhilash on 2006-08-05. It has been viewed 19641 times.
Rating of 5.6 with 249 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