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?
|
|