TRT
Sign in
easyFoundationsconcept

Where do function calls keep their data and return addresses?

Describe frames, push and pop order, backtraces, leftover locals, and the cause of a stack overflow.

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

The Runtime Theory Team2 min read
Learn it firstThe Call Stack: What Happens When a Function Is CalledFollow nested function calls as frames pushed onto and popped off the stack: the return address, parameters and locals of each call, why locals contain leftovers, and what a stack overflow is.

A strong answer

A strong candidate frames Where do function calls keep their data and return addresses? around the exact memory layout, compiler semantics, and hardware execution model covered in The Call Stack: What Happens When a Function Is Called. Describe frames, push and pop order, backtraces, leftover locals, and the cause of a stack overflow.

The last lesson said that every call creates fresh parameters and locals, and that they vanish when the call returns. But where do they live? A function can call another function that calls a third, and the machine must remember, for every call that is still in progress, its variables and the place where it should resume. With recursion, which comes in lesson 9, the very same function can be in progress many times at once.

The stack. Each thread of a program gets a block of memory used as a last-in, first-out structure, called the call stack. A CPU register, the stack pointer, marks its top. On x86-64 and on most ARM systems the stack grows toward lower addresses, so pushing something moves the pointer down.

In a production interview, always connect the specification rule to its concrete runtime consequence: state what lives on the stack versus the heap or static storage segment, how the compiler or operating system validates alignments, lifetimes, and error codes, and what happens under adversarial or boundary inputs (such as zero-length buffers, integer overflow, concurrent mutation, or partial I/O). Backing your explanation with a small trace of register/memory state transitions immediately separates senior systems engineers from candidates who only memorized syntax.

What the interviewer is listening for

  • Mastery of core invariant: Describe what is pushed onto the stack when a function is called and what is popped when it returns.
  • Mastery of core invariant: Read a backtrace as the chain of active calls, innermost first.
  • Mastery of core invariant: Explain why uninitialized local variables contain leftover values.
  • Hardware and ABI awareness: Explaining how sizes, alignments, calling conventions, or kernel boundaries behave on real 64-bit targets rather than relying on implementation-defined assumptions.
  • Defensive engineering: Naming the exact compiler flags (-Wall -Wextra -Werror), static analyzers, or runtime sanitizers (-fsanitize=address,undefined,thread) that verify correctness in CI.

Common mistakes

  • Explaining only surface syntax without tracing the underlying memory addresses, ownership lifetime, or kernel/user-space state transitions.
  • Assuming undefined behavior (such as signed overflow, uninitialized reads, strict-aliasing violations, or dangling pointers) will "just work" because it passed an unoptimized -O0 debug build.
  • Ignoring return codes, partial reads/writes, alignment padding, or cleanup paths when an allocation or syscall fails midway through a function.

This answer walks

Practice follow-ups

  1. 01How do you read a backtrace, and which frame ran most recently?

Not started

Sign in to save your learning progress.

Sign in to save