C/C++ Arena

Step 2 of 5

Pass by reference

Reference parameters let a function modify the caller's variables with none of the pointer noise:

void heal(int& hp) { hp = 100; }

int hp = 12;
heal(hp);        // no & at the call site

Your turn: write void swap_values(int& a, int& b).

Previous: References are aliases Next: const references