previous | index | next

Simulating Call by Reference

We can explicitly pass the addresses of p and q:

...
swap(&p, &q);
...

Q: How must swap be changed?

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

However, this only simulates call by reference; true call by reference allows the call

...
swap(p, q);
...


previous | index | next