Stack Frame and Call Stack

The call stack tracks active function calls.

Every function call creates a stack frame and pushes it on stack. When function returns → frame popped.

So stack follows LIFO.


What is inside a stack frame?

Usually includes:

Actual layout depends on compiler + ABI (x86_64/ARM).


Example call stack

main()
  |
  +-- funcA()
        |
        +-- funcB()

Stack while inside funcB:

Top
+-------------------+  funcB frame
| locals of funcB   |
| return → funcA    |
+-------------------+  funcA frame
| locals of funcA   |
| return → main     |
+-------------------+  main frame
| locals of main    |
+-------------------+
Bottom

Function Call Flow Diagram

Function Call Flow

Visualizes the function calling sequence and how stack frames are created and destroyed using LIFO behavior during nested function calls.


Stack Overflow

Occurs when stack memory exceeds limit.

Common causes:


One stack per thread

Each thread has its own stack.