Hi,
Can someone please explain how is the control stack cleared when we exit from a function?or who clears the rescords in the control stack?
Thanks
Hi,
Can someone please explain how is the control stack cleared when we exit from a function?or who clears the rescords in the control stack?
Thanks
The stack is never "cleared". When a function exits, the stack pointer is "aimed" at the return address. The stuff that was pushed onto the stack for the exited function remains there, until it is overwritten by the next function call.
This is why uninitialized automatic variables(the ones whose memory is allocated on the stack) contains leftover garbage from the previous function that was stored at the address on the stack.