One line swap of integers source code

This snippet submitted by abhilash on 2006-08-05. It has been viewed 9806 times.
Rating of 5.9 with 161 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!