Memory and Addresses

Pointers have a scary reputation, but the idea is simple. Let's start with how memory works.

Memory is a long street of houses

Your computer's memory is like a very long street. Every house has a number (its address), and each variable lives in a house. When you write int age = 30;, C++ picks a house, puts 30 in it, and remembers that age means that house.

Think of it like this: The variable's value is what's inside the house (30). The address is the house number written on the door. Two very different things!

Seeing an address: &

Put & in front of a variable to get its address. Addresses are usually shown in hexadecimal (numbers with letters a–f, starting with 0x):

#include <iostream>
using namespace std;

int main() {
    int age = 30;
    double price = 9.5;
    cout << "age lives at   " << &age << "\n";
    cout << "price lives at " << &price << "\n";
    return 0;
}

Output (your addresses will be different)

age lives at   0x109f88
price lives at 0x109f80

You never choose addresses yourself and they change between runs. What matters is the idea: every variable has one.

Remember: Here & means “address of”. (In a type like int& it means reference. Same symbol, two jobs – the position tells you which.)

HOME LABS COMMUNITY DASHBOARD