Pointers = Links

Jeff Venancius
2 min readFeb 4, 2023

--

Pointers are easy to understand, they are just Links.

Yeah, that’s it, if you go low-level they are a address number to a variable, but thinking about them as Links to a website makes more sense, I guess.

The hard stuff is not the concept, but how we apply them — and some of it I think is a language problem.

I mean, in C/C++ at least, when it comes to pointers, they are too abstract.

Let’s say you have a pointer, but the actual value of that pointer is https://dataptr.com, which refers to a variable that contains the actual data.

char data[] = “Actual data”;
char *ptr_data = &data;

Now, the * means that I want a pointer, the & means I want the address of the data, the “Link” to the “website” we’re dealing with. — which is, for explaining purposes, https://dataptr.com .

Now, if I do this:

ptr_data = "another data";

Will the https://dataptr.com be turned into “another data”?

No, that’s not what is going to happen.

Instead, the data variable will transform into “another data”, it will change the “website”, not the address.

It makes sense? No, but it just works, and that is the problem when you’re trying to learn something — That you can’t understand something that “it just works”.

But anyway, that’s how it happens, if you say a pointer = something you’re actually saying that the value that lives inside the address is gonna be = something.

It’s abstraction when you actually needs to know what you’re doing.

Why would I want pointers?

That’s the same reason why you want websites, with pointers you can access the same data anywhere and change it, without it it’s just a copycat.

Another idea I can think of is saving and loading a game, would you rather play the game till you reach the part you were before or you rather access the data that says “hey, that’s where you are, go on”?

Because that’s what you do when you pass an argument to a function without pointers, you copy the data into it, which means that you repeat what is right there already.

Now, I want to get the value instead of set it, what will I do?

Will I do this?

char old_data[] = ptr_data;

No, I won’t do this. You know why? Because NOW it works as you normally expects to work.

To get the actual value, you need to add the *, like this:

char old_data[] = *ptr_data

Yeah, that’s it, I think I understand now, but I probably don’t.

Anyway, pointers are easy.

This is part of a series I’m calling TheDuckTeacher, where I explain to myself concepts that I don’t really understand as I learn them.

Yeah, I came up with this name from the Rubber duck debugging technique.

--

--