Return statement

In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address.

Uses your system voice; voice and rate in settings.

≈ 3 min read

Cite, export and learn8 citation formats · 8 exports · lesson and quiz

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is saved by the calling routine, today usually on the process's call stack or in a register.

Return statements in many programming languages allow a function to specify a return value to be passed back to the code that called the function.

Syntax

Return statements come in many shapes. The following syntaxes are most common: In some assembly languages, for example that for the MOS Technology 6502, the mnemonic "RTS" (ReTurn from Subroutine) is used.

Yield statements

Cousin to return statements are yield statements: where a return causes a subroutine to terminate, a yield causes a coroutine to suspend. The coroutine will later continue from where it suspended if it is called again. Coroutines are significantly more involved to implement than subroutines, and thus yield statements are less common than return statements, but they are found in a number of languages.

Call/return sequences

A number of call/return sequences are possible depending on the hardware instruction set, such as the following: The CALL instruction pushes address of the next instruction on the stack and branches to the specified address. The RETURN instruction pops the return address from the stack into the instruction pointer and execution resumes at that address.

(Examples: x86, PDP-11) In architectures such as the Motorola 96000, the stack area may be allocated in a separate address space known as the Stack Memory Space, distinct from the main memory address space. The NEC μPD7720 also features a stack with its own separate address space.

The CALL instruction places address of the next instruction in a register and branches to the specified address. The RETURN instruction sequence places the return address from the register into the instruction pointer and execution resumes at that address.

(Examples: IBM System/360 and successors through z/Architecture, most RISC architectures) The CALL instruction places address of the next (or current ) instruction in the storage location at the call address and branches to the specified address+1. The RETURN instruction sequence branches to the return address by an indirect jump to the first instruction of the subroutine.

(Examples: IBM 1130, SDS 9XX, PDP-8)

See also

Return type Exit status

Text derived from https://en.wikipedia.org/w/index.php?oldid=1359237580 under CC BY-SA 4.0; modifications have been made.

Words in each sectionCall/return sequencesCall/return sequencesCall/return sequences: 206 words206Yield statementsYield statementsYield statements: 64 words64SyntaxSyntaxSyntax: 34 words34See alsoSee alsoSee also: 25 words25
Words in each section. Measured from the stored article body; sections below the minimum are not plotted.

Provenance

snapshot enwiki-001359237580 · captured 2026-06-13 · ledger · version history

Cite this page as: encyclopegia.org, “Return statement”, snapshot enwiki-001359237580. https://encyclopegia.org/a/return-statement

Sources cited in this revision

20 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.