What is a pointer in programming?
Last updated: 2026-11-26
A pointer is a value whose job is to name where another value lives, and much of the confusion about it comes from mixing up two moves: changing where the pointer points, and changing the value it points to. Wikipedia's definition puts it plainly: a pointer stores a memory address, and reading the value at that address is called dereferencing. The article's analogy is a page number in a book index: the entry is small, and flipping to the page is dereferencing.
Start learning No account needed
1. The pointer and the pointed-to are different things
Keep the two objects straight and the rest follows. There is the pointer, a small variable holding a location, and there is the thing at that location, which can be as large as you like. Writing through the pointer changes the pointed-to thing and leaves the pointer alone. Rebinding the pointer changes only which location it names, and leaves the thing alone. Both moves look like an assignment in code, which is exactly why people swap them: p.value = 99 and p = other look alike, but the first changes the node and the second changes only what p refers to.
One reason to use pointers is cost. Wikipedia's article notes that copying and dereferencing a pointer often costs far less time and memory than copying the data itself, and lists the structures built on that trade, linked lists and trees among them, where pieces of the structure hold the locations of other pieces. That is why section 2's second half counts link rewires: a chain that stores locations can grow without moving what is already stored.
2. A worked example: the two moves, then a counted rewire
Ordinary Python code works with references rather than raw addresses, so the example models pointers with object references, which behave the same for these two moves. The script runs both, then counts the writes needed to splice a new node into a chain:
a = Node(1); p = a: p and a name the same node: True
move 1, write through the pointer: p.value = 99, so a.value is now 99
move 2, rebind the pointer: p = Node(2), so p.value is 2 and a.value is still 99
inserting c after a rewires 2 links and moves no values
chain from a: 99, 7, 5
a pointer left holding a freed location is the dangling-pointer bug;
Python frees an object only once nothing refers to it, so this
script models the two moves and does not reproduce that bug
checks passed
Read move 1 against move 2. In move 1, p.value = 99 follows the pointer and edits the node it names; because a names that same node, a.value reads 99 afterward. In move 2, p = Node(2) points p somewhere else; a's node is untouched and still reads 99. If a trace of your own code surprises you here, check which of the two moves each line performs before checking anything else.
The counted splice is the payoff. Inserting node c after a in a chain takes two link writes, c.next = a.next and then a.next = c, and moves no stored values; the chain from a then reads 99, 7, 5. The order matters, and doing the second write first would strand the rest of the chain. Wikipedia's linked list article gives the same two assignments, in the same order, for inserting a node after an existing one.
3. A common misconception: the pointer is the value
Picture a student who reads p = Node(2) and expects to find 2 inside the node a names, or who writes p.value = 99 believing only p changed. Both lines run without errors, so no error message points at the mistake. One habit that helps is to annotate each assignment with its target: "this line changes the pointer" or "this line follows the pointer and changes the thing." When a trace surprises you, reread the annotations on the lines before the surprise.
A related idea is the dangling pointer, where the pointed-to memory goes away but the pointer stays behind. Wikipedia's article on it gives the C-shaped version, memory freed while a pointer still holds its location, and one guard, resetting the pointer to null after freeing, which does not clear other copies of that pointer. It is a different bug from the one above, but the same distinction explains it: the pointer holds a location, and what lives there can change or go away while the pointer stays as it was. The article adds that garbage-collected object-oriented languages prevent dangling references by destroying only unreachable objects, so the Python script names the bug without running it.
4. Test yourself
Close this page and write two lines of code: one that changes the value the pointer names, and one that changes where the pointer points. Then, for each, say what a second name for the same node would observe afterward. If you cannot answer the second half, reread move 1 and move 2 above; that observable difference is the part to study again.
For the surrounding course, see how to study for a computer science exam and how to learn programming without copying code. For checking an answer without help, see how to test yourself.
What the sources found, and their limits
Wikipedia, "Pointer (computer programming)". It defines a pointer as an object that stores a memory address, names dereferencing as reading the value there, gives the page-number analogy, motivates pointers by the cost of copying data, and lists the structures built on them, linked lists and trees included, along with the null and dangling kinds. Source: Pointer (computer programming), read on 2026-11-25.
Wikipedia, "Dangling pointer". It gives the shape of the bug this page names in section 3 and the FAQ: a pointer left holding a location after its memory is freed, the unpredictable behavior that can follow, resetting to null as one guard and that guard's limit with copies, and the note on garbage collection. Source: Dangling pointer, read on 2026-11-25.
Wikipedia, "Linked list". Its operations section inserts a node after an existing one with two assignments, the order our script uses. Source: Linked list, read on 2026-11-25.
Python documentation, "Execution model". It says that names refer to objects, which our FAQ answer relies on. Source: Execution model, read on 2026-11-25.
Limits: three encyclopedia articles and one page of Python's documentation, not a language course. The Node model, the counts and every printed value are ours, computed by scripts/what-is-a-pointer-in-programming-worked-example.py; the page does not reproduce the dangling-pointer bug because Python frees an object only once nothing refers to it, and the script says so in its output. No memory addresses appear anywhere on this page, on purpose. The Wikipedia articles are CC BY-SA and the Python documentation is under the PSF License.
How Professor Turing helps
Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.
Bring the line of code that surprised you, such as a reassignment that left a shared object unchanged. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of handing over the answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through. You must be 18 or older, and guest conversations are deleted 7 days after the last activity.
FAQ
Does Python have pointers? Not the way C does. Python's documentation says that names refer to objects, which is why the worked example on this page uses references to model the two moves instead of printing memory locations. Wikipedia's pointer article calls a pointer a more concrete form of the reference idea, and says the word applies most properly where a program can manipulate the address, for example with arithmetic. The test p is a returning True shows two names referring to one object, much like two pointers holding the same address. The same distinction, changing the thing or changing where you point, carries over to C pointers.
What is a dangling pointer? A pointer that no longer points to a valid object, for example because the memory was freed while the pointer kept its value. Wikipedia's dangling pointer article warns that the system may reuse that memory, so using the old pointer can behave unpredictably. One guard in C is to set the pointer to null right after freeing, though other copies of the pointer stay dangling. The article notes that garbage-collected object-oriented languages prevent dangling references, so this page names the bug without reproducing it.
Start with what you're working on
Tell the tutor which move you are tracing and let it ask you the questions.
Start learning No account needed
See also: how to learn programming without copying code · how to study for a computer science exam · how to test yourself · array and linked list · pass by value and pass by reference · all study guides