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;
}


previous | index | next