How does the stack work in a function call?
Anonym
The address of the location where the function is called (also called return address) is pushed to the top of stack, along with any local variables within the scope of the caller. Then, execution jumps to the address of the called function (callee) and all local variables within the scope of the callee are pushed on to the stack. When the called function ends, all its local variables are popped from the stack, and execution goes back to the return address, where local variables of the caller function are again brought into scope.