From: tyan@cs.cornell.edu (Thomas Yan) Newsgroups: cornell.class.cs100 Subject: Idiom for swapping two variables Date: 2 Feb 2000 20:05:05 GMT in section last week, you should have seen this idiom (common, well-known code sequence) for swapping two int variables x and y: int tmp; tmp = x; x = y; y = tmp; this is something you should be able to do/use without thinking hard about it. [remark: this is perhaps not so well-known, but if you want to "toggle" variable x between two values A and B, i consider this to be a nice way to do it: x = A + B - x; ]