Python Unmasking Memory: Pointers & Addresses (& and *)
Pointers are the superpower that gives C++ unmatched speed and hardware control. Every variable sits at a physical address in RAM (e.g. 0x7ffd5e). The & operator retrieves a variable's address, and a pointer variable (int *ptr) stores that address. The * dereference operator accesses the value at that address.
"Think of a house. The furniture inside is the variable value (e.g. 42). The street address written on the mailbox (e.g. "742 Evergreen Terrace") is the memory address (&). A pointer is a piece of paper with that address written down. Looking at the paper gives you the address; driving to the address and opening the door is dereferencing (*)."
Deep Dive: How It Works
Address-Of Operator (&): &var returns the hexadecimal memory location where var lives in RAM.
Pointer Declaration (*): int *ptr = &var; (ptr is a pointer variable storing the memory address of an integer).
Dereference Operator (*): *ptr reads or writes the actual value sitting at that address (*ptr = 99; changes the original variable!).
nullptr: Always initialize pointers to nullptr if they don't point to a valid address yet, preventing dangerous wild pointer bugs.
Syntax Blueprint
int score = 100; int *ptr = &score; // 1. Store address std::cout << *ptr; // 2. Dereference (prints 100) *ptr = 200; // 3. Mutates score to 200!
& gets memory address, int * creates pointer, * dereferences target.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Confusing int *ptr = &val with *ptr = valWhy it happens: The asterisk (*) means two different things: creating a pointer type vs dereferencing an address.
How to fix: In declaration, * denotes pointer type. In expressions, * means "go to this address".
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Mutate a variable via pointer
Declare int health = 80; and int *ptr = &health;
Set *ptr = 100;
Print "Health: 100".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.