C Program to Swap two variables without using third variable ?

How to write a C Program to Swap two variables without using third variable in C Programming Language ?


#include<stdio.h>
int main(){
    int a=5,b=10;
/* Type (a)*/
    a=b+a;
    b=a-b;
    a=a-b;
    printf("a= %d  b=  %d",a,b);

/* Type (a)*/
    a=5;
    b=10;
    a=a+b-(b=a);
    printf("\na= %d  b=  %d",a,b);
/* Type (a)*/
    a=5;
    b=10;
    a=a^b;
    b=a^b;
    a=b^a;
    printf("\na= %d  b=  %d",a,b);
   
/* Type (a)*/
    a=5;
    b=10;
    a=b-~a-1;
    b=a+~b+1;
    a=a+~b+1;
    printf("\na= %d  b=  %d",a,b);
   
/* Type (a)*/
    a=5,
    b=10;
    a=b+a,b=a-b,a=a-b;
    printf("\na= %d  b=  %d",a,b);
    return 0;
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable



Learn More :