Pointer
In one line
A pointer is a variable that stores the memory address of another value, rather than the value itself.
In simple words
A pointer is a variable that does not hold a regular value — it holds the ADDRESS of where a value lives in memory. Think of it like a forwarding address: instead of holding the person, it holds the location where you can find the person.
Pointers are explicit in low-level languages like C and C++, where you manually manage memory addresses. In higher-level languages like JavaScript and Python, pointers exist behind the scenes as "references" — when you assign an object to a variable, the variable holds a reference (pointer) to the object, not a copy.
Understanding pointers/references is crucial for understanding why let a = obj; let b = obj; makes a and b point to the SAME object — modifying through one affects the other. This is called "reference semantics" and is a common source of bugs for beginners.
Example
// JavaScript uses references for objects
const obj1 = { count: 0 };
const obj2 = obj1; // obj2 points to the SAME object
obj2.count = 5;
console.log(obj1.count); // 5 — changed through obj2!
// Primitives are copied by value
let a = 5;
let b = a;
b = 10;
console.log(a); // 5 — unchangedobj1 and obj2 are references (pointers) to the same object. Changing through one is visible through the other. Primitives are copied by value, so changing b does not affect a.
Common confusions
Confused with: reference
The difference: A pointer is an explicit memory address (C/C++); a reference is an abstract handle managed by the language (JavaScript/Python/Java). References are safer but less flexible.
Related terms
Related Resources
Related Lessons
- Memory and References
Learn about memory and references.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.