Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!nic.MR.NET!shamash!tank!gargoyle!ddsw1!olsa99!oct1!proxima!lucio From: lucio@proxima.UUCP (Lucio de Re) Newsgroups: comp.lang.c Subject: Re: Brain Teaser Message-ID: <1272@proxima.UUCP> Date: 7 Apr 90 11:55:03 GMT References: <10289@wpi.wpi.edu> Reply-To: lucio@proxima.UUCP (Lucio de Re) Organization: FLAGSHIP Wide Area Networks - Cape Town Lines: 25 In article <10289@wpi.wpi.edu> oesterle@wpi.wpi.edu (Shawn H. Oesterle) writes: >Problem: > Swap two pointers without using a third pointer. >Hint: > Two numbers may be swaped without using any other memory by executing > the following statements: > > int x, y; /* or you can chose double, long, etc. */ > > x += y; > y = x - y; > x -= y; Well, I'd never have thought of it, thanks. Might be useful when programming the i8051. As for the pointers swap, I suppose you can't do the same because you need an integer in the middle. Maybe a cast will save you, but is it worth it (or portable?). ---------------------------------------------------------------------- I used to design nuclear reactors and you should see the code that engineers and scientists come up with. Yuuuck! Spaghetti everywhere. -------------------------------------------------- (Kenneth L Moore) - Lucio de Re ...uunet!ddsw1!olsa99!proxima!lucio -------------------------------------------------------- lucio@proxima Disclaimer: He must have been joking!