Pointers explained:

4 months ago by ZILtoid1991 to c/programmer_humor

lime 108 points 4 months ago

they used to call him the deref king back in college

path: 0 24160354, hotness: undefined, score: 108, children: 0
lian_drake 73 points 4 months ago

Worse version of this

path: 0 24162130, hotness: undefined, score: 73, children: 11
ZILtoid1991 6 points 4 months ago

Null termination is no longer recommended, use fat pointers instead!

path: 0 24162130 24167420, hotness: undefined, score: 6, children: 0
mbp 3 points 4 months ago

Why would I want to be shown the concept of pointers by an eight year old?

path: 0 24162130 24164308, hotness: undefined, score: 3, children: 8
WrathEnchanter 15 points 4 months ago

I'll have you know, she's canonically 300 years old

path: 0 24162130 24164308 24165540, hotness: undefined, score: 15, children: 6
wieson 15 points 4 months ago

Nah, she's 5 or younger. She lied about being 6 (school age) to get adopted. It's a very wholesome story (if you disregard the war, political intrigue and terrorism).

path: 0 24162130 24164308 24165540 24167793, hotness: undefined, score: 15, children: 4
mnemonicmonkeys 5 points 4 months ago

And the fact that Anya's best friend is trying to break up Anya's parents because she has a crush on the dad

path: 0 24162130 24164308 24165540 24167793 24169160, hotness: undefined, score: 5, children: 1
WrathEnchanter 2 points 4 months ago

I was just making a joke

path: 0 24162130 24164308 24165540 24167793 24182251, hotness: undefined, score: 2, children: 0
HeyThisIsntTheYMCA 2 points 4 months ago

El terrorismo makes it more holesome.

path: 0 24162130 24164308 24165540 24167793 24182150, hotness: undefined, score: 2, children: 0
mbp 2 points 4 months ago

🙄

path: 0 24162130 24164308 24165540 24171161, hotness: undefined, score: 2, children: 0
rizzothesmall 5 points 4 months ago

It's a good reference (lol) even if it's getting downvoted

path: 0 24162130 24164308 24165332, hotness: undefined, score: 5, children: 0
hoohoohoot 0 points 3 months ago
path: 0 24162130 24742449, hotness: undefined, score: 0, children: 0
NullPointerException 67 points 4 months ago

Wait. It’s been a long time but shouldn’t be int*** -> int** -> int* -> int ?

path: 0 24160445, hotness: undefined, score: 67, children: 15
Susaga 83 points 4 months ago

I think int*** is meant to be pointing at int**, but the image is just unclear about where everything is in perspective.

path: 0 24160445 24160549, hotness: undefined, score: 83, children: 11
dohpaz42 28 points 4 months ago

Pretty sure the image is clear:

int*** -> int*
int** -> int
Int* -> int

Clarity doesn’t mean correct. But that’s probably why it’s posted here. 🤷‍♂️

path: 0 24160445 24160549 24162057, hotness: undefined, score: 28, children: 9
mexicancartel 9 points 4 months ago

int** is inside a TV, and persumably int* must be inside another TV(even though uts not edited in). The image perespective is showing one thing inside the other, inside the other. So when when int*** points the TV it reference int**, which reference int* which reference int. Its just edited very bad

path: 0 24160445 24160549 24162057 24164660, hotness: undefined, score: 9, children: 0
Susaga 8 points 4 months ago

RT*** isn't pointing at RT*, he's pointing at the TV showing RT**. The fact you think otherwise is what makes the image unclear. I'm not sure why you insist on them being wrong.

path: 0 24160445 24160549 24162057 24167183, hotness: undefined, score: 8, children: 1
_tasten_tiger 0 points 4 months ago

But that doesn't hold up, because RT** isn't pointing at a TV containing RT* only RT*** is pointing at an TV containing RT** RT* and RT

path: 0 24160445 24160549 24162057 24167183 24207239, hotness: undefined, score: 0, children: 0
MonkderVierte 2 points 4 months ago

What's the * for again?

path: 0 24160445 24160549 24162057 24166408, hotness: undefined, score: 2, children: 5
Monument 4 points 4 months ago

It’s to check to see if commenters know how to escape the symbol. Congratulations! You passed!

Source: I made it up.

path: 0 24160445 24160549 24162057 24166408 24168382, hotness: undefined, score: 4, children: 3
HeyThisIsntTheYMCA 2 points 4 months ago

That one's a typo

path: 0 24160445 24160549 24162057 24166408 24182196, hotness: undefined, score: 2, children: 0
obviouspornalt 15 points 4 months ago

I mean, that's pretty much what happens to me every time I try to use pointers, so the meme checks out.

path: 0 24160445 24160549 24163091, hotness: undefined, score: 15, children: 0
Quibblekrust 7 points 4 months ago

path: 0 24160445 24175646, hotness: undefined, score: 7, children: 0
terranoid 7 points 4 months ago

yep this is just someone misunderstanding pointers lol

path: 0 24160445 24160533, hotness: undefined, score: 7, children: 0
Dialectical_Specialist 3 points 4 months ago

That's not the end of the chain either, right?

Because : int -> &int -> &&int

Or can you not use the address operator like that? It also might be int& &, I failed cs2200 on this exact type of technicality

path: 0 24160445 24162367, hotness: undefined, score: 3, children: 0
DrCake 41 points 4 months ago

Rumble Tumble Games in the wild

path: 0 24160252, hotness: undefined, score: 41, children: 1
MrQuallzin 12 points 4 months ago

Seeing him break containment is wild

path: 0 24160252 24161577, hotness: undefined, score: 12, children: 0
MrNesser 30 points 4 months ago

Didn't expect to see the Drift King here

path: 0 24167385, hotness: undefined, score: 30, children: 1
Jumi 9 points 4 months ago

Drift King? You mean Dan the Villian

path: 0 24167385 24169777, hotness: undefined, score: 9, children: 0
dangrousperson 11 points 4 months ago

as a python script kiddie, this is way over my head, but upvoted because of RT Game

path: 0 24167486, hotness: undefined, score: 11, children: 0
14th_cylon 8 points 4 months ago

Why should the left one in the rectangle be int**? It doesn't make sense to me, they are both clearly just int*

What am i missing?

path: 0 24160473, hotness: undefined, score: 8, children: 2
ImgurRefugee114 9 points 4 months ago

I they're supposed to be pointing at each other but the edit didn't really work because his arm is pointing too far away

path: 0 24160473 24160874, hotness: undefined, score: 9, children: 0
Skipcast 4 points 4 months ago

Perspective innit

path: 0 24160473 24161534, hotness: undefined, score: 4, children: 0
MonkderVierte 8 points 4 months ago

So, googling it, the general premise is you should use smart pointers instead to avoid crashes. Got it.

path: 0 24166427, hotness: undefined, score: 8, children: 8
DahGangalang 10 points 4 months ago

Smart pointers implies C++, which is not the right answer.

path: 0 24166427 24167534, hotness: undefined, score: 10, children: 2
MonkderVierte 6 points 4 months ago

Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written C++ book. It is way too big and complex for doing this. In fact, it is so big and complex, that there are very many very bad C++ books out there. And we are not talking about bad style, but things like sporting glaringly obvious factual errors and promoting abysmally bad programming styles.

https://stackoverflow.com/...

path: 0 24166427 24167534 24169049, hotness: undefined, score: 6, children: 1
mnemonicmonkeys 6 points 4 months ago

Considering that most of the "answers" I've found on StackOverflow were complete dogshit, I'm wary of this reading list

path: 0 24166427 24167534 24169049 24169133, hotness: undefined, score: 6, children: 0
HeyThisIsntTheYMCA 5 points 4 months ago

Uh

I think I'll just let the cat drive instead

path: 0 24166427 24182189, hotness: undefined, score: 5, children: 0
CanadaPlus 4 points 4 months ago

They all have footguns that cause different crashes.

If you want to do explicit memory access without inevitable safety problems, you need Rust. That's the whole hype with Rust.

path: 0 24166427 24174543, hotness: undefined, score: 4, children: 3
MonkderVierte 1 point 4 months ago

But... per-process-isolation is a hardware feature, no?

path: 0 24166427 24174543 24184015, hotness: undefined, score: 1, children: 2
CanadaPlus 2 points 4 months ago

Sure, that may be (it's definitely not in userspace). But don't forget it works by crashing your program.

path: 0 24166427 24174543 24184015 24191566, hotness: undefined, score: 2, children: 0
psud 2 points 4 months ago

So you really should implement it in your compiler so you don't contravene it

path: 0 24166427 24174543 24184015 24244461, hotness: undefined, score: 2, children: 0
Technus 7 points 4 months ago

Real talk: is there any practical use-case for T*** of any pointee type?

path: 0 24160899, hotness: undefined, score: 7, children: 7
palordrolap 22 points 4 months ago

Dynamically allocated multidimensional arrays.

path: 0 24160899 24161003, hotness: undefined, score: 22, children: 6
Technus 12 points 4 months ago

Ah right, so that would be a 3D array.

  • T* is a single row of T
  • T** is a list of rows
  • T*** is a list of "layers" in the third dimension

This would be incredibly hazardous to pass around as a bare pointer with no context, though. I'd expect to see this in a struct that, at minimum, also includes fields for the size of each dimension.

path: 0 24160899 24161003 24161160, hotness: undefined, score: 12, children: 1
BartyDeCanter 8 points 4 months ago

This Sparta C. We live for danger.

path: 0 24160899 24161003 24161160 24162943, hotness: undefined, score: 8, children: 0
Auth 8 points 4 months ago

Tesseract Array

path: 0 24160899 24161003 24161401, hotness: undefined, score: 8, children: 0
MonkderVierte 1 point 4 months ago

Where?

path: 0 24160899 24161003 24166434, hotness: undefined, score: 1, children: 2
palordrolap 3 points 4 months ago

In the C programming language. Or do you mean which C project specifically? Because as Technus surmises in their response, it's usually a better idea to set up aliases (typedefs or heck, even #defines) so that you're offloading some of the mental strain keeping track of the layers, and that's likely to be what happens in production code.

But the underlying data type is still T***.

path: 0 24160899 24161003 24166434 24167782, hotness: undefined, score: 3, children: 1
MonkderVierte 1 point 4 months ago
path: 0 24160899 24161003 24166434 24167782 24167995, hotness: undefined, score: 1, children: 0
LovableSidekick 5 points 4 months ago

C# delegates enter the chat and nod.

path: 0 24162306, hotness: undefined, score: 5, children: 0
refalo 4 points 4 months ago

that's not LaurieWired

path: 0 24179202, hotness: undefined, score: 4, children: 0
Quibblekrust 4 points 4 months ago

Am I a computer scientist now?

path: 0 24175213, hotness: undefined, score: 4, children: 1
ZILtoid1991 0 points 4 months ago

No, you need to learn a lot more. Other programming concepts, programming paradigms, algorithms, and many more.

path: 0 24175213 24175288, hotness: undefined, score: 0, children: 0
Flames5123 4 points 4 months ago

Now that explain the & part of the pointers that I never really understood.

path: 0 24165178, hotness: undefined, score: 4, children: 14
ZILtoid1991 6 points 4 months ago

The & operator references the value.

int i;
int* p = &i;

In C++, the & at the function argument makes it a reference type (safe pointer).

void someFunction(int& refVal) {
    [...]
}
path: 0 24165178 24165511, hotness: undefined, score: 6, children: 12
Flames5123 1 point 4 months ago

As someone who likes working with higher level languages, I never understood the pass by reference or even referencing different pointers. It never stuck out to me as useful in what I want software to do. It’s too close to hardware.

path: 0 24165178 24165511 24166015, hotness: undefined, score: 1, children: 11
lime 10 points 4 months ago

if you're working with higher level languages you pass-by-reference all the time. give a list to a function to modify it? that's by reference. giving an event handler function to a framework? that's by reference. setting a property on an object? that's usually by reference.

path: 0 24165178 24165511 24166015 24166713, hotness: undefined, score: 10, children: 7
funkless_eck 0 points 4 months ago

the list is the helpful part to understanding it.

it would be terrible if, with bar being a list and foo being a member of the list

 if foo in bar: return true

modified the list. So yeah, you want to look at the list not edit the list, it's a pointer.

path: 0 24165178 24165511 24166015 24166713 24166749, hotness: undefined, score: 0, children: 6
Sylvartas 10 points 4 months ago

Most of the time you pass by reference for more outputs, or by const ref to avoid copying a big-ass data structure (which is not always straightforward, with structures smaller than a pointer, which are pretty big in 64 bits architecture, you lose more to the ref overhead than to the copy IIRC)

path: 0 24165178 24165511 24166015 24167185, hotness: undefined, score: 10, children: 1
DahGangalang 4 points 4 months ago

Another reason I commonly see: to change the structure / "main pointer" to a data structure (esp during freeing and cleanup).

path: 0 24165178 24165511 24166015 24167185 24167557, hotness: undefined, score: 4, children: 0
ZILtoid1991 1 point 4 months ago

Reference values are quite useful, such as:

double valOut;
if (parseDouble(valOut) == 0) { //Argument of parseDouble is ref type, no & needed for input, no exceptions needed for error handling
    [...] //No error, code executed normally
} else {
    [...] //Erroreus input
}
path: 0 24165178 24165511 24166015 24166272, hotness: undefined, score: 1, children: 0
dejected_warp_core 4 points 4 months ago

*x = dereference or "point to". Treats the variable x as containing a pointer value. Evaluates to a variable existing at the address in x.

&x = reference or "get address of". Evaluates to the address of x.

They're complimentary operators, so *(&x) cancels out and is equvalent to just x.

path: 0 24165178 24172935, hotness: undefined, score: 4, children: 0
itkovian 3 points 4 months ago

So, confusing, nonetheless.

path: 0 24161736, hotness: undefined, score: 3, children: 0
HeyThisIsntTheYMCA 3 points 4 months ago

Uh I'm a charisma class (with unfortunate base stats) what's int

path: 0 24182141, hotness: undefined, score: 3, children: 1
zerofk 3 points 4 months ago

It’s what makes mages turn those squiggly lines on paper into fireballs.

Not clerics though, they’re different.

path: 0 24182141 24182638, hotness: undefined, score: 3, children: 0
Deconceptualist 3 points 4 months ago

The placement of the labels is a bit sloppy but I think it tracks. The character in the middle (int*) is pointing at int, then the one on the left (int**) is pointing at the middle one (int*), etc

What I want to know: what is that shirt and where do I get it?

path: 0 24162784, hotness: undefined, score: 3, children: 2
addie 2 points 4 months ago

He dereferenced a pointer to the 1970s and retrieved the shirt that way.

path: 0 24162784 24166511, hotness: undefined, score: 2, children: 1
Deconceptualist 2 points 4 months ago

So it's like a mystical artifact of the computational Big Bang? You deref a pointer to the very beginning of Unix time and bam, suddenly you're styling like Richard Stallman?

path: 0 24162784 24166511 24174797, hotness: undefined, score: 2, children: 0
programmer_humor
programmer_humor

@programming.dev

login for more options
33694
2569
7739

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn't find it funny, you're banned. Ha-ha!... For real: do not use the community for "statements". There are other places for such content. Keep it chill and funny.

go to feed...