The Runtime Theory
mediumRuntimeInternals#explain-the-model#reason-about-tradeoffs

Explain What a Function Call Places in a Stack Frame

Explain the model, execution steps, complexity, and limits of what a function call places in a stack frame.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team6 min read

Interview prompt

Explain what a function call places in a stack frame to an engineer who understands the surrounding system but has not used this technique. Walk from its contract to a concrete operation, then discuss where it fails or becomes expensive.

A strong answer

A function call transfers control while preserving enough state for the caller to resume. A calling convention defines how arguments, return values, registers, and stack alignment are handled. A stack frame commonly holds saved registers, local storage, and bookkeeping, though optimizers can keep values in registers or remove frames.

When function A calls B, the machine records a return location and passes arguments according to the platform ABI. B may reserve stack space and save registers it must preserve. On return, it places the result where the caller expects and restores the control state required by the convention.

A complete answer also calls out the assumptions that control correctness. Recursion creates nested activation state and can exhaust a finite stack. Tail-call elimination can reuse a frame when language and compiler rules permit it, but should not be assumed across every runtime. Stack layout and calling conventions vary by architecture and compiler.

Close by describing one representative test or measurement. Trace a recursive function with input depth three. At each call, list the values that must remain available for the suspended caller after the deeper call returns.

Follow-up questions

Answer the follow-ups in the frontmatter. Use the linked article for the concept and the trace to make the explanation concrete.

This answer walks

Practice follow-ups

  1. 01Which assumption is essential for the approach to be correct?
  2. 02What is the worst case, and how does it change the resource cost?
  3. 03How would you adapt the design if the input or workload became much larger?
  4. 04What boundary test would give you the most confidence in the implementation?

One dispatch a week

The trace behind each question, the tradeoff that explains it, and one technical dispatch per week — no noise.

One technical dispatch per week. No noise.

Not started

Sign in to save your learning progress.

Sign in to save