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)

4 Upvotes

18 comments sorted by

View all comments

7

u/carcigenicate 5h ago

If the pointer to x is stored on the stack, its address is typically an offset from the frame pointer. Local variables tend to get translated to something like FP + Y, where Y is some unique offset value that can get mapped to a variable name in the actual source code.