Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!ukc!edcastle!aiai!ken From: ken@aiai.ed.ac.uk (Ken Johnson) Newsgroups: comp.lang.c Subject: Obfuscated SWAP Keywords: swap Message-ID: <784@skye.ed.ac.uk> Date: 23 Aug 89 10:14:50 GMT Reply-To: ken@aiai.UUCP (Ken Johnson) Followup-To: comp.lang.c Organization: AIAI, University of Edinburgh, Scotland Lines: 31 Well, I tried it and it works, at least in the example I chose. This code main( ) { int x, y; x = 12; y = 3; x ^= y ^= x ^= y; /* Swap X and Y over */ printf("x = %d\ny = %d\n",x,y); } produces this output: x = 3 y = 12 I don't understand how it works, but I do now understand why C programmers have a reputation for going around showing each other bits of paper and saying `I bet you can't guess what this does!' -- Ken -- Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 212 `I have read your article, Mr. Johnson, and I am no wiser than when I started.' -- `Possibly not, sir, but far better informed.'