How to Explain Pointers to Normies


Nobody has ever asked me what a pointer is IRL, but here’s what I would say if they did.

You know how when we text message, we don’t send a full song, or a 60 minute movie? We instead send the name of a song or a movie.

This is a reference to something, AKA a pointer to the information.

The other person then uses this knowledge to “find” the corresponding information, perhaps finding the song on YouTube or looking for the movie on NetFlix.

In programming we call this dereferencing, i.e. using the reference to obtain the information for usage.

Why is this useful? Two main reasons.

Sometimes, it’s more convenient (thus faster). Even though we could send a full song, it’s easier just to send the song name. Sending a full video would definitely suck. Similarly, in code it’s easier to manipulate the pointer (which is just an integer) than a big chunk of data.

Sometimes, it’s more flexible (thus more useful). You might choose to view the song on YouTube, or download it in high quality on a streaming platform, whereas if I just received a raw mp3 song, I’m stuck with that. If I send someone Shrek in Japanese with Swedish subtitles burnt in, that’s how they’ll have to consume it. Similarly, I can decide how to use the pointer, such as copying it, iterating over it as a list, or copying its contents in their entirety.

That’s it, I hope this explanation you never asked for was useful.

Discuss on Hacker News

← Back to home