Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> A pointer is a variable that contains the address of a variable.

Doesn't it technically also contain its own address? So it contains the address of another variable and the address of itself. Pointers are hard...



A variable "contains" only its (current) value. That's the only use of "contains" that makes sense to me.

You can "get" the address of a variable (or more generally, of any l-value) with the & operator. That operator is nothing else but an "escape" character that says "Dear C, I don't want you to load the current value of that variable. Give me just the address where it lives so I can load it later".

(Same applies to storing instead of loading)


> Doesn't it technically also contain its own address

Huh? Then you probably don't understand the meaning of "contains" here. Or what variables are in general. Variables are hard...


Well, the way I see it is this: you, as a person, contain your thoughts and possessions and so on - call it your value. But you also exist in space and time, you have a defined location. You don't carry it in your pocket, it's something you implicitly contain.


Nope. And they're not really. Imagine a simple computer with, say, 32 bytes of ram.

All our bytes of ram are numbered. We read a value from byte number 8 and that value is 17.

"Byte number 8" is a pain to remember or calculate so we give it a label and let the computer keep track. That's a "variable".

What does that 17 mean though? Is it a value we want to use later on? It might be. Or it could be referring to Byte 17 in our ram. Byte 17 happens to have the value 42 so if we use Byte 8 as a pointer that's the value we end up with.

But it's entirely our choice. It's just a number and we can treat it as a value or a pointer to another memory address as we like.


No, that would be a pointer to a pointer.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: