Path: utzoo!attcan!uunet!cs.utexas.edu!wuarchive!husc6!m2c!wpi!oesterle From: oesterle@wpi.wpi.edu (Shawn H. Oesterle) Newsgroups: comp.lang.c Subject: Brain Teaser Keywords: { void * x, * y; x <-> y; } Message-ID: <10289@wpi.wpi.edu> Date: 27 Mar 90 18:23:30 GMT Reply-To: oesterle@wpi.wpi.edu (Shawn H. Oesterle) Organization: Worcester Polytechnic Institute, Worcester, MA Lines: 33 Problem: Swap two pointers without using a third pointer. Example: { void * x, * y, * tmp; tmp = x; x = y; y = x; } Make a piece of code which has the same effect as this, but without using the 'tmp' variable (in C, of course). 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; Answer: I don't know, that's why I'm asking you! Shawn Oesterle {oesterle@wpi.wpi.edu}