/* --------------------------------------------------------------------- ** Figure 12.8: A swap function that works. ** --------------------------------------------------------------------- */ #include "tools.h" void swap( double * fp1, double * fp2 ); void main( void ) { double x = 10.2, y = 7; printf( "Before swap: x=%5.1g y=%5.1g\n", x, y ); swap( &x, &y ); printf( "After swap: x=%5.1g y=%5.1g\n", x, y ); } /* ---------------------------------------------------- */ void swap( double * fp1, double * fp2 ) { double swapper = *fp1; *fp1 = *fp2; *fp2 = swapper; } /* Output --------------------------------- Before swap: x= 10.2 y= 7.0 After swap: x= 7.0 y= 10.2