0Pricing
C++ Academy · Lesson

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 20

All lessons in this course

  1. Why References Aliases for Variables
  2. Pass-by-Value vs Pass-by-Reference
  3. const References and When to Use Them
  4. Reference Lifetime and Dangling References
← Back to C++ Academy