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.
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.
"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.
The python interpreter uses pointers all the time. A list or an array in python? That's just pointers to a list of pointers. Python saves you that trouble. It also denies you the power that comes with controlling the granularity. C, does not. C gives you live ammo, and trusts you to not shoot yourself.
It's not even that it trusts you. It trusts you no more than a rock and a high cliff trusts you. The makers never cared what you would do with it. You can shoot yourself all day. You want a safety? Make one with C and make a library that you reference. You'll want to use "pointers" in that solution; they make for cheap data integrity.
What does the python interpreter use to pass objects that hold memory references? And that name, it may be a label, that references a computer science term. What term is that?
The language itself is not the same as its implementation; rather, it is defined by its specification. Otherwise, C wouldn't "exist" without a compiler either!
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.