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.

17

u/Marxomania32 Apr 24 '24

Being able to do arithmetic on pointers and be able to arbitrarily dereference them is what makes them pointers. Other languages have references, which almost certainly end up being implemented with a pointer somewhere underneath the hood, but that doesn't make them pointers.

-5

u/lokithegregorian Apr 24 '24

"Pointer" is a lexeme of all programming languages. Like "instantiate," "reference," "object," or "value." It is the object holding your reference (usually to memory). It has a size. I can set other variables equal to it. I can pass it in functions. I can operate on the pointer, with or without de-referencing said pointer.

It doesn't matter what the language calls them. They are simply rebranding a pointer.

https://en.wikipedia.org/wiki/Pointer_(computer_programming)

1

u/glasket_ Apr 24 '24

You should read the Reference page instead. Pointers are only one kind of reference, and the underlying implementation of a language has no impact on what its type system actually conveys.

If you aren't directly interacting with a pointer type, you aren't using a pointer; you're using a reference which may or may not act as an abstraction over a pointer within the implementation.

1

u/lokithegregorian Apr 24 '24

A reference would be the literal. If I set a variable equal to that literal, what is that variable now called?