C/C++ Arena

Step 1 of 5

References are aliases

A reference is another name for an existing variable. Declare one with & after the type:

int hp = 100;
int& ref = hp;   // ref IS hp
ref -= 30;       // hp is now 70

Unlike pointers, a reference must be initialized, can't be null, and can't be re-pointed later. No * or -> needed to use it.

Your turn: make alias a reference to money, then spend 800 through it.

Next: Pass by reference