Brain Teaser

Michael Condict condict at
Fri Apr 13 00:15:37 AEST 1990

In article <2039 at awdprime.UUCP>!ibmchs!auschs!!sanders (Tony Sanders) writes:
|In article <10289 at> oesterle at (Shawn H. Oesterle) writes:
|-	{
|-		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).
|This is really quite easy AND ANSI compliant.
|You see, to "make a piece of code which has the same effect" as your
|sample code, this will suffice:
|    void *x, *y;
|    x = y;
|If you don't believe me then double check your sample code.

Actually, the sample code can be optimized more than that.  It is exactly
equivalent to the following statement:

since the variables are all local to the block.
Michael Condict		condict at
Vrije University

More information about the Comp.lang.c mailing list