The memory paradox

Surely when allocating memory you get an address that it is written to , but how do you then store that address for later use? the thought I had would be having it reallocated to a stack each time. Any one able to explain?

It’s kept on the stack, which is tracked via a stack pointer that is in turn kept in a register, which you always have access to.
Precise implementation may vary slightly, but that’s the gist.

The initial stack pointer is given to you by the OS when it allocates the stack for your process, so if you want to continue down the rabbit hole, that’s where you would go.

There, FTFY :slight_smile:

Ah, fair point.