References in C++
A reference (int& r = x;) is an alias — a second name for existing storage, not a copy and not a nullable pointer. It must bind at declaration and can never rebind, which removes whole categories of pointer bugs (no null, no arithmetic, no reseating) while keeping zero-cost access.
References dominate function parameters (const& for inputs, & for outputs) and range-based for loops. Rvalue references (&&) extend the idea to temporaries, powering move semantics — same syntax family, different job: stealing resources instead of copying them.
Alias, not object
int& r = x; makes r another name for x — no new storage, no null state, no separate address to manage.
Bind once, forever
A reference binds at initialization and cannot be reseated — r = y later assigns y's value into x, never rebinds r.
Parameters are the home turf
const std::string& in (read-only view) and int& out (writable slot) cover nearly every function signature worth writing.
&& is a different beast
Rvalue references bind temporaries and enable moves — same & family look, but about ownership transfer, not aliasing.
#include <iostream> void addTax(double& price) { price *= 1.1; } int main() { double price = 100.0; addTax(price); int& alias = (int&)price; (void)alias; std::cout << price << std::endl; return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C++ yourself — building beats watching.