#include /* * This is the C++ way * there are not references "&" in C * you have to pass the address explicitly * void swap ( int & x, int & y ) { int tmp = x; x = y; y = tmp; } */ void swap ( int * x, int * y ) { int tmp = *x; *x = *y; *y = tmp; } int main() { int a = 3; int b = 5; printf ( "a = %d, b = %d\n", a, b ); swap ( &a, &b ); printf ( "a = %d, b = %d\n", a, b ); return 0; }