Download this source file


/* swap.c - uses pointers to implement a swap function.
 * Written 2001 by Wayne Pollock, Tampa Florida USA.
 */

#include <stdio.h>

void swap ( int*, int* );  // swaps the contents of two ints.

int main ( void )
{
   int i1 = 7, i2 = 22;
   printf( "Before calling swap: " );
   printf( "i1 = %2i, i2 = %2i\n", i1, i2 );
   swap( &i1, &i2 );
   printf( "After calling swap:  " );
   printf( "i1 = %2i, i2 = %2i\n", i1, i2 );

   return 0;
}


void swap ( int* a, int* b )
{
   int t = *a;
   *a = *b;
   *b = t;
}




Send comments and mail to pollock@acm.org.