Development (General)

What is a pointer in programming?

What a pointer is and how it works: memory addresses, dereferencing, sharing data without copying, and the bugs that null and dangling pointers cause.

  • 6 min read
  • 5 questions
  • +35 XP
Transcript

Pointers, explained by cats. Kitty has a bowl of tuna on the table. Very tasty tuna. Instead of carrying the bowl everywhere, Kitty writes a sticky note. The sticky note says “Tuna is on the table.” That sticky note is a pointer.

The pointer is not the tuna. It just tells Kitty where the tuna lives. Another kitty gets the sticky note. They go to the table. Same tuna. No copying. But danger exists. If the tuna bowl is thrown away, And the sticky note stays, Kitty follows it…

And finds nothing. Sad kitty. That's a Null Pointer Exception Pointers mean You don’t move the tuna. You move the note that points to it. The tuna stays put. The note tells the truth. Until it doesn’t.