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.

0

u/Jonny0Than Apr 24 '24

Strong disagree on "the hard part." Dangling pointers, double-free, memory leaks, and buffer overruns are much harder to prevent and debug, and they're all (mostly) unique to C/C++. And that's *on top of* the concept of references.

4

u/EpochVanquisher Apr 24 '24

My experience from teaching—once people have a good grasp of pointers, that’s the hard part, and the other stuff built on top of it is a lot easier. When people have a hard time with double-free, it’s often because they don’t understand that an object and the reference to the object are separate objects, and changing one doesn’t affect the other.