One line swap of integers source code

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