Memory Addresses and the Address-of Operator
You'll learn how every variable lives at a unique memory location and how to find that location using the address-of operator.
What is a Memory Address?
Think of your computer's memory like a massive apartment building. Each apartment has a unique street address so mail carriers know exactly where to deliver packages. Similarly, every variable you create gets stored at a unique memory address — a number that identifies exactly where in RAM that variable lives.
When you declare a variable like int x = 42;, the value 42 gets stored somewhere in memory. The memory address is the numerical location (often written in hexadecimal, like 0x7ffeabcd1234) that tells the computer where to find x.
The Address-of Operator (&)
The address-of operator (&) is your way of asking: "Where does this variable live in memory?" When you write &x, you're not getting the value of x — you're getting its address.
Analogy: If x is a person's name, then &x is asking for their home address. The name tells you who they are; the address tells you where they are.
Why This Matters
Understanding memory addresses is foundational for working with linked data structures (coming soon). Instead of storing all data in one contiguous block like arrays, linked structures use addresses to connect separate pieces of data scattered throughout memory — like leaving breadcrumbs that point to the next location.
You've already seen that arrays are stored contiguously in memory. Memory addresses let us break free from that constraint and build more flexible structures.
Key Takeaway: Every variable has a unique memory address, and the address-of operator (&) retrieves that address, giving you the location where the variable's value is stored rather than the value itself.