previous | index | next

More on Argument Passing

Q: Will the following swap function work?

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

A: No, because parameters a and b receive copies of p and q, so the original values are not affected.

Needed: a way to bypass C++'s policy of call by value (passing copies of arguments) and implement call by reference (passing addresses of arguments).


previous | index | next