9.1 — Memory and addresses

📘 Chapter 9⏱ about 1 min read✍️ Beginner friendly
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 x
Output
0x7ffd5b2c4a1c

The & 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.

Finished reading? Tick it off. Your progress is saved in this browser.

Tip: press ← / → to move between lessons, / to search.