Listing 7 A swap function that illustrates call-by-reference

//swap.cpp
#include <stdio.h>

void swap(int &, int &);

main()
{
   int i = 1, j = 2;

   swap(i, j );
   printf("i == %d, j == %d\n",i,j);
   return 0;
}

void swap(int &x, int &y)
{
   int temp = x;
   x = y;
   y = temp;
}

// Output:
i == 2, j == 1

// End of File