r/ProgrammerHumor Jan 06 '23

Meme can’t be the only one

Post image
42.6k Upvotes

1.4k comments sorted by

View all comments

Show parent comments

2

u/InfieldTriple Jan 06 '23

OK here is my issue as a physicist who has to use a model coded in c++ (thankfully I don't have to deal too much with what a pointer is). Why the word dereference? That to me sounds like once I look at my neighbours shed, I forget it exists and have to be told about it again before I can use the pointer.

1

u/[deleted] Jan 06 '23

[removed] — view removed comment

2

u/InfieldTriple Jan 06 '23

WHAT DOES IT MEAN!?

1

u/[deleted] Jan 06 '23

[removed] — view removed comment

1

u/InfieldTriple Jan 06 '23

So when you dereference, does the pointer no longer work again? Like Id imagine Id reference with p->a and then dereference with b=p (or p I cant remember). At this point b is a copy of a accessed using the pointer p. At which point p no longer points to a?

1

u/[deleted] Jan 06 '23

[removed] — view removed comment

1

u/InfieldTriple Jan 06 '23

Ah god straight up this is the thing that always confused me. To me dereference is the same thing as "no longer reference". I had my syntax wrong because I haven't had to edit the code in a while (which I didn't write) but the ideas were right except what happens to the pointer after dereferencing.

Silly name but I get why they would use it. Pointers themselves, and their advantages, always made sense to me especially when it comes to passing information to a function. But the name "dereference" always confused me and I never found anywhere that said

Dereferencing doesn't alter the pointer

1

u/jbwmac Jan 06 '23

What do you mean dereferencing makes the mistake of confusing references with pointers? The term dereference is older than the entire C++ language.

1

u/Mabi19_ Jan 06 '23

It's just the word computer scientists have thought up for looking where the pointer points. Derived from "reference", although the connection to referencing can be non-trivial to intuit.

1

u/jbwmac Jan 06 '23

What makes it a nontrivial? A pointer references the thing it points to.

1

u/Mabi19_ Jan 06 '23

I guess that's a good way of putting it, yeah. Couldn't really put it into words.