9.1 — Memory and addresses
Read one box at a time. No rush.
Every box has an address#
Your computer's memory is like a very long street of boxes. Each box has a number: its address.
When you make a variable, C++ picks a box (or a few boxes) for it.
C++
int x { 42 };std::cout << &x; // prints the address of xOutput
0x7ffd5b2c4a1cThe & in front of a variable means "address of". Addresses are usually shown in hexadecimal (base 16), starting with 0x.
Key idea
A variable has a value (what's inside the box) and an address (where the box is).
Why care?#
Addresses let different parts of a program share the same box instead of making copies. That is what references and pointers are for.
Tip: press ← / → to move between lessons, / to search.