Home

callandreturn

Call and return, or call-and-return control flow, is the fundamental mechanism by which a program transfers execution from a caller to a subroutine and later resumes at the point of departure after the subroutine finishes. A call passes arguments to the callee and transfers control to the subroutine’s entry point; a return transfers control back to the caller and may supply a result.

Implementation typically relies on a call stack. The caller pushes a return address and arguments according

Tail calls are a notable optimization in which the callee immediately returns to the caller, allowing the

Call and return is distinct from other control-flow constructs such as coroutines, generators, or asynchronous callbacks,

Historically, subroutine calls emerged in early languages such as Fortran and Algol and became the dominant

to
a
calling
convention,
then
jumps
to
the
subroutine.
The
callee
creates
a
stack
frame
for
its
local
variables
and
parameters,
executes,
and,
when
finished,
places
any
return
value,
restores
the
previous
stack
frame,
and
returns
to
the
saved
address.
The
exact
mechanics—how
arguments
are
passed,
where
the
return
address
is
stored,
and
how
stack
frames
are
managed—vary
by
language,
compiler,
and
hardware.
current
stack
frame
to
be
replaced
rather
than
grown.
When
supported,
tail-call
optimization
enables
efficient
recursion
and
long
chains
of
calls.
though
many
languages
combine
them.
It
also
interacts
with
exception
handling
and
stack
unwinding;
errors
may
bypass
normal
returns
and
trigger
unwinding
of
the
call
stack.
method
for
structuring
programs
in
imperative
languages
like
C,
Java,
and
many
others.
The
precise
behavior
is
determined
by
the
language’s
calling
conventions
and
the
underlying
hardware
architecture.