
If you started your coding journey with Python or JavaScript, "pointers" might sound like some arcane dark magic reserved for systems engineers with grey beards. Even if you learned C++ in college, you probably remember struggling with segmentation faults and memory leaks.
But here is the secret: a pointer is just a variable. It’s not magic. It’s a number. That number just happens to be the address of something else.
To really understand pointers, we first need to talk about where your data actually lives.
When your code runs, your data has to go somewhere. Generally, it lands in one of two places: the Stack or the Heap.
Imagine the Stack like a stack of sticky notes on your desk.
If you have a variable int a = 10;, it likely sits here. It’s clean, fast, and safe.
The Heap is a giant warehouse.
A pointer is simply a signpost.
If you have a variable score = 99 on the Heap (at address 0x1234), a pointer is just a tiny variable on the Stack that says "The data is at 0x1234".
int score = 99; // The actual value
int *p = &score; // The pointer 'p' holds the address of 'score'p is the address (where is it?).*p is the value (what is inside?).Why not just pass values around and let the language handle the mess?
Imagine you have a 10MB image. If you pass it to a function process(image), and your language copies that image, you just wasted 10MB of RAM and CPU time copying pixels.
With a pointer, you just pass the address (8 bytes). You tell the function: "The image is over there, go look at it."
If you pass a variable by value to a function, the function gets a clone. If it changes the clone, the original is untouched. If you pass a pointer, the function knows where the original lives. It can modify the actual data.
Linked lists, trees, graphs—these are just chunks of data holding pointers to other chunks of data. You can't build them easily without references.
Pointers aren't free.
Pointers are the bridge between your code and the hardware. Even if you write high-level JavaScript or Python, understanding that objects are just references (pointers!) under the hood helps you understand why a = b might not copy b, but just point a to the same data.
Mastering pointers gives you x-ray vision into how your code executes. You stop seeing "magic" and start seeing memory.
© Melvin Laplanche - All rights reserved.