Concept:
When a function is called, the system needs to store information about the current state so it can return to it later.
• Activation Record (Stack Frame): A block of memory containing the function's parameters, local variables, and the return address.
• LIFO Principle: The last function called is the first one to finish and return.
Step 1: Analyzing function call behavior.
Function calls follow a nested structure. If Function A calls Function B, then B must complete before A can continue. This "Last-In, First-Out" (LIFO) behavior is perfectly modeled by a Stack.
Step 2: Managing local variables.
The local variables of a function only exist as long as the function is executing. When the function returns, its variables are "popped" off the memory structure. The stack allows for efficient, automatic allocation and deallocation of this memory.
Step 3: Conclusion.
The Runtime Stack (or System Stack) is the dedicated area of memory used specifically for this purpose. Every time a function is invoked, its activation record is "pushed" onto the stack.