Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!gatech!galbp!advdev.LBP.HARRIS.COM!jsb From: jsb@advdev.LBP.HARRIS.COM (FLEA) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Message-ID: <8514@galbp.LBP.HARRIS.COM> Date: 22 Aug 89 19:12:30 GMT References: <8350@boring.cwi.nl> Reply-To: jsb@advdev.UUCP (FLEA) Organization: /etc/organization Lines: 21 In article <8350@boring.cwi.nl> tromp@piring.cwi.nl (John Tromp) writes: : (Timothy R. Gottschalk) writes: : :> To swap two variables x,y in C without using a temporary variable: : :> /* begin swap */ :> x += y; :> y = x - y; :> x -= y; :> /* end swap */ : :> Just curious...(this looks pretty valid) does anyone know an even : :How about : :x^=y^=x^=y; : :Avoids possible overflow problems and looks great in an :Obfuscated C Code entry too! Sorry, folks, both of these are illegal if x and y are pointers.