Why References Aliases for Variables
Introduce references as compile-time aliases that cannot be reseated or null.
What is a Reference?
A reference is a compile-time alias for another variable. It is not a pointer and not a copy — it is the same object under a different name.
Reference Syntax
Use & after the type. References must be initialized at declaration and cannot be reseated.
int x = 10;
int& ref = x; // ref is an alias for x
ref = 20; // x is now 20All lessons in this course
- Why References Aliases for Variables
- Pass-by-Value vs Pass-by-Reference
- const References and When to Use Them
- Reference Lifetime and Dangling References