| | | | | |

Runtime Stack and Recursion

  • Runtime environment (Ada, C, C++, Java, Pascal ...)
    • Contiguous address space allocated by OS
    • [static | stack -->      ...      <-- heap]
    • static: executable codes, symbol table, global variables
    • stack: push/pop for every function call/return
    • Current active call at top of stack
    • heap: new/delete dynamic memory
    • If stack and heap collide then program crashes
  • stack = stack < AR > // AR = Activation Record
    • Function name and code location (in static)
    • Function parameters
    • Function return value
    • Control return location
  • Recursion
    • Order 1: function calls itself
    • Order 2: F() calls G(), G() calls F()
    • Facilitated by stack

| | Top of Page | 5. Abstract Data Types: Stacks and Queues - 16 of 22