Quick variable swapping.

A function that can swap 2 variables without using another. Very quick.

^

See version :

Pas de dépendances

Download :

#include <stdio.h>

void swapint(int* a,int* b)
{
    *a = *a ^ *b;
    *b = *a ^ *b;
    *a = *a ^ *b;
}

void swapint2(int* a,int* b)
{
    *a ^= *b ^= *a ^= *b;
}

void swapint3(int* a,int* b)
{
    (*a)+=(*b)-=(*a)=(*b)-(*a);
}

void swapint4(int* a,int* b)
{
    (*a)/=(*b)=((*a)=(*a)*(*b))/(*b);
}

void swapint5(int* a,int* b)
{
    (*a)=((*b)=((*a)=(*b)^(*a))^(*b))^(*a); 
}

void swapint6(int* a,int* b)
{
    (*b)=(*a)+(*b)-((*a)=(*b));
}

int main()
{
    int a,b;
    a = 135;
    b = 2834;
    swapint(&a,&b);
    printf("a = %d ; b = %d\n",a,b);
    return 0;
}



Explanations

	No explanations yet.