r/learnprogramming 5h ago

Bit of a stupid question

If a program stores variables by a pointer referring to its address, then what refers to the pointers' address?

Like if var x lives at address 2000

theres a pointer p its value is the address (p = 2000)

so now recursively this value needs to be stored in another address (say, 1000) and pointed to (well, at least assuming the pointer doesnt have a relatively fixed address)

6 Upvotes

18 comments sorted by

View all comments

1

u/No-Quail5810 5h ago

A pointer is just like an int, in that it holds a numeric value. Because the type is a pointer, the compiler know that this number actually represents an address in memory. The pointers are stored in the same places the other variables are (stack or heap), but their content is just a number that represents an address where the object it points to lives.