A pointer does not hold data — it holds the address of data. That one twist unlocks the heap.
1 Pointer = address
A pointer variable stores the location of another variable, not a value itself.
2 & reads an address
&box asks "where does box live?" — the answer is what a pointer stores.
3 * follows the address
*p travels to wherever p points and reads or writes the value there.
4 new and delete
new reserves memory on the heap at runtime; delete hands it back. You are the cleanup crew.
Why pointers?
Pointer = address1A pointer variable stores the location of another variable, not a value itself. & reads an address2&box asks "where does box live?" — the answer is what a pointer stores. * follows the address3*p travels to wherever p points and reads or writes the value there. new and delete4new reserves memory on the heap at runtime; delete hands it back. You are the cleanup crew. 4 building blocks make up Why pointers?
Drag to orbit. Play the script: p learns where age lives, then writes through the arrow.
Drag to orbit the scene. Press Play to watch memory in action.
Heap memory is rented, not owned — follow one int through the whole cycle.
Press play — new builds an int on the heap, the pointer works on it, delete releases it.
preprocessThe preprocessor pastes in iostream for cout.
Memory
no variables yet — press play
Console
output appears as the program runs…
A pointer aims at box — what do the two lines print?
Your predicted output — one line per console line
Hint: p stores the address of box — writing through *p changes box itself, so the second read sees the new value.
Click a term, then click its description to lock the pair.
6 conceptsTap a card to expand ?int* pdrops into place
?&boxdrops into place
?*pdrops into place
?new int(7)drops into place
?delete pdrops into place
?nullptrdrops into place
01A pointer stores an address; * follows it and & reads one.
02new reserves memory on the heap at runtime; delete returns it.
03Every new deserves one delete — miss it and memory leaks.
04After delete, set p = nullptr so it cannot be used by accident.
05Stack variables clean themselves up; heap memory is your job.