Brain Teaser

Shawn H. Oesterle oesterle at wpi.wpi.edu
Wed Mar 28 04:23:30 AEST 1990


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 at wpi.wpi.edu}



More information about the Comp.lang.c mailing list