r/C_Programming • • Apr 24 '24

The way C Programers explain pointers

https://imgs.xkcd.com/comics/pointers.png
652 Upvotes

50 comments sorted by

View all comments

30

u/EpochVanquisher Apr 24 '24

There are pointers in most languages.

The difference is that C calls them “pointers”, makes you manage lifetime manually, and lets you do arithmetic on pointers. But the hard part about learning to use pointers is not any of the things unique to C; instead, it’s understanding conceptually how object references work; it’s understanding that two different references can refer to the same object.

It’s one of the most common gotchas that trips up beginners in Python, for example.

2

u/erikkonstas Apr 24 '24

Weirdly enough, I have understood pointers for longer than I've understood references 😂 it's almost like mastering pointers is kinda necessary to understand references, and even then I still needed some practice with those... before that I just knew about Python's "quirky" way (Markdown messed up here) a = b = [] works without considering the deep details of it...

0

u/EpochVanquisher Apr 24 '24

Yeah—the thing is, a = b = [] works the same way in Python as it does in, like, most languages, with a couple exceptions like C++. Like, Java, C#, JavaScript, Go, and Ruby all work the same way as Python does. C++ is the weird one for copying lists by default, if you are using something like std::vector.

1

u/erikkonstas Apr 24 '24

Yeah it took some time to realize that hey, it's just a reference, even though there's no reference to "reference" here (aside some CPython-specific stuff)! is and the id built-in also make much more sense now...