Guided Notes

References & Pointers

References as aliases, pass-by-reference, memory addresses and pointers, nullptr, dynamic memory, and smart pointers.

References

Slide 1 / 5

A reference is another name for an existing variable: int score = 80; int& ref = score; ref += 5; // score is now 85

• A reference must be initialized and can't be re-pointed later. • Functions taking references can change the caller's variables: void addBonus(int& points) { points += 10; } • const references let functions read big objects without copying: void print(const std::string& text);

← Arrays & Vectors