P-3.2 Pointers, and What They Are For
Standard C pointer semantics — written September 2026
What this is and why it exists
Pointers have a reputation they do not deserve. It was earned by being taught as syntax rather than as an idea.
Here is the idea. A pointer is a variable holding an address. You already know an address is a number. Every rule about pointers follows from that, plus the size of the thing being pointed at.
The real difficulty is somewhere else entirely, and it is worth naming now. A pointer to storage that no longer exists looks exactly like a valid one. Nothing about it announces the problem.
The vocabulary
- Address-of — taking the number identifying where a variable lives.
- Dereference — going to that location to read or write.
- Pointer arithmetic — adding to a pointer, which moves it by whole elements.
- Null pointer — a pointer that deliberately points nowhere.
- Dangling pointer — an address that was valid a moment ago and is not now.
The mental model
Taking the address of a variable gives you a number saying where it lives. Dereferencing goes to that location. That is the entire concept, and everything else about pointers is consequence and notation.
The first consequence is the one that motivates them. Arguments are copied, so handing over an address is how a function reaches back into its caller and changes something there. This is why pointers appear in the first week of a C course rather than the last: they answer a question you already have.
The second consequence is arithmetic, and it surprises people once. Adding one to a pointer advances it by one element, not one byte. The type is what tells the compiler how far that is. Get the type wrong and the arithmetic silently reads memory belonging to something else, with no complaint from anyone.
A null pointer points nowhere on purpose. It is how a function reports that it has nothing to return. Following one stops the program — and it is worth being clear that this is the *good* outcome. The alternative is following a pointer to storage that happens to contain something, and continuing with nonsense.
Which brings us to dangling pointers, the genuinely hard case. When storage is released, or a function returns, addresses into it become meaningless. They do not change. They keep looking like ordinary numbers, because that is what they are. Reading through one sometimes works, depending on what has reused the space since. That intermittency is what makes these so hard to find. The same code passes on Monday and crashes on Thursday, and nothing in it changed.
What you should now be able to explain or do
Declare a pointer, take an address, and dereference it. Explain why passing an address lets a function change its caller's value. Say what adding one to a pointer does, and why the type decides it. Say what a null pointer is for and why following one stopping the program is the good outcome. Explain what a dangling pointer is and why it is so hard to find.
Check yourself
What is a pointer, in one sentence?
A variable holding an address, which is a number identifying a location in memory. Everything else follows from that.
Why does adding one to a pointer not add one byte?
Because it moves by one element of the pointed-to type. The type is what tells the compiler how far one element is.
Why is a crash on a null pointer the good outcome?
Because it stops immediately at the fault. The alternative is following an address that happens to hold something and carrying on with nonsense.
What makes a dangling pointer hard to find?
It looks identical to a valid pointer, and reading through it sometimes works. The failure depends on what reused the space, so it comes and goes.
Where do dangling pointers come from?
Released storage, and addresses into a function's locals after it has returned. In both cases the address survives the thing it pointed at.
Go deeper
We haven't checked most of these for screen reader use yet.
- CS50x: Introduction to Computer Science · Harvard / CS50 · Courseneeds a free account
Back to Pointers, and What They Are For: work through the checklist