What happens to the stack when exiting a method?

后端 未结 6 398
长发绾君心
长发绾君心 2021-01-01 20:53

I was reading What and where are the stack and heap?. One thing I am a bit fuzzy on is what happens to the stack after a method exits. Take this image for example:

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 21:51

    Is the pointer at the stack just moved back to the start of the stack making it empty?

    the pointer at the stack is moved back to where it was before the function call. The stack would not be empty because it contains data that belongs to calls that brought the program to that point.

    To illustrate: if func1 called func2 called func3 the stack will look something like this:

    func1 args/local vars... | func2 args/local vars... | func3 args/local vars...

    After func3 returns it will be:

    func1 args/local vars... | func2 args/local vars...

提交回复
热议问题