1 2 3 4 5 6 7 8 9 10 11 12

void swap (int* a, int* b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
with invocation


swap ( &A, &B);
Although this works fine, it is easy to forget and make
mistakes. In C++ things are improved, somewhat, by
allowing parameters to be declared as references,
instead of pointers, and so we write:


void swap (int& a, int& b)
{
int tmp;
tmp = a;
a = b;
b = tmp;
}
with invocation:
swap (A, B);// Just like in Fortran!
// but is it any better?

March 2,1998

Page 10

C201 TAM/AGS