One way is to use the xor operation, although it doesn't always work: Code: a^=b; b^=a; a^=b; You should find out under what circumstances it doesn't work (by testing that is, not by posting "give me coding plz" somewhere).