Q40: What is Tail Call Optimization (TCO)?

Tail Call Optimization occurs when a recursive function call is the final execution statement inside a function. The engine reuses the current stack frame instead of allocating new stack frames, preventing stack overflow errors on infinite recursion.

Key Takeaways
  • Reuses call stack frame when recursion occurs at tail position.
  • Prevents Maximum call stack size exceeded errors on deep recursions.
Knowledge Check

Which requirement must be met for a function to qualify for Tail Call Optimization?