C中的范围和返回值

我再次以c开始,正在考虑变量的范围。
如果我在一个函数内部有一个变量,然后我返回该变量,变量在返回时不会被“死”,因为它的范围已经结束了

我已经尝试了一个函数返回一个字符串,它做的工作。
有人可以解释一下吗或者至少指出我可以解释一下这个地方。

谢谢

When the function terminates, the
following steps happen:

  • The function’s return value is
    copied into the placeholder that was
    put on the stack for this purpose.

  • Everything after the stack frame
    pointer is popped off. This destroys
    all local variables and arguments.

  • The return value is popped off the
    stack and is assigned as the value
    of the function. If the value of the
    function isn’t assigned to anything,
    no assignment takes place, and the
    value is lost.

  • The address of the next instruction
    to execute is popped off the stack,
    and the CPU resumes execution at
    that instruction.

The stack and the heap

相关文章
相关标签/搜索