550
Pointers explained: (thelemmy.club)
you are viewing a single comment's thread
view the rest of the comments
[-] funkless_eck@sh.itjust.works 0 points 1 week 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.

[-] gerryflap@feddit.nl 2 points 6 days ago

Your example doesn't make sense to me. Why would you modify the entire list by checking if something is in it? Also, you can totally edit the list via a pointer, that's how you're supposed to edit the list if you want any performance. Otherwise you'd be copying the list on every modification, which is terribly inefficient

[-] Sylvartas@lemmy.dbzer0.com 1 points 6 days ago* (last edited 6 days ago)

A pointer to the list would allow you to modify whatever's at that pointer's address though. If you want to look at the list and not edit it you pass by const reference 99% of the time (or you pass a copy) and if your language doesn't have that I don't like it.

[-] captcha_incorrect@lemmy.world 2 points 6 days ago

I still don't get the point of pointers.

I want my language to pass by reference. I give a variable to a function and the variable in the function scope should be a reference to the same place in memory as the original variable.

How can pointers help me here? What value does it provide? Genuine question.

[-] Sylvartas@lemmy.dbzer0.com 2 points 6 days ago* (last edited 6 days ago)

I want my language to pass by reference. I give a variable to a function and the variable in the function scope should be a reference to the same place in memory as the original variable.

I'm not even a C++ wizard or anything (though it's my most advanced language) so I'm not gonna argue that is good or bad, that sounds fine to me for a wide range of applications already.

But the way is see it, pointers kinda allow you to use "raw memory" which is an actual thing that's gonna be handled by the program one way or another, and it's a way to relatively refer to memory for example. As some guy on stackoverflow put it "That guy at the end for the bar" vs "Bob" can be very useful. Especially when using data structures you don't know the size of at compile time.

[-] captcha_incorrect@lemmy.world 2 points 4 days ago

I had to implement drag and drop in a Windows application recently. Since you don't know the content type nor the size of the content, pointers has to be used, which makes sense. For the most part when working within the bounds of my own application, I haven't found a good use case for pointers. That could of course be because I am not used to thinking in that way.

[-] lime@feddit.nu 4 points 1 week ago

other way round surely? if you want to modify the original object, use a pointer. if you don't, use a copy.

this post was submitted on 08 Jun 2026
550 points (94.4% liked)

Programmer Humor

31836 readers
500 users here now

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

founded 3 years ago
MODERATORS