Summary
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. In C and C++, return exp; (where exp is an expression) is a statement that tells a function to return execution of the program to the calling function, and report the value of exp. If a function has the return type void, the return statement can be used without a value, in which case the program just breaks out of the current function and returns to the calling one. In Pascal there is no return statement. (However, in newer Pascals, the Exit(exp); can be used to return a value immediately. Without parameters, it just breaks out the procedure.) A subroutine automatically returns when execution reaches its last executable statement. Values may be returned by assigning to an identifier that has the same name as the subroutine, a function in Pascal terminology. This way the function identifier is used for recursive calls and as result holder; this is syntactically similar to an explicit output parameter. The same syntax is used in Fortran 66 and Fortran 77 although a return statement was added in FORTRAN II. In some other languages a user defined result variable is used instead of the function identifier. Oberon (Oberon-07) has a return clause instead of a return statement. The return clause is placed after the last statement of the procedure body. This enables compile-time checking of proper return and return value from the procedure. Some expression-oriented programming language, such as Lisp, Perl and Ruby, allow the programmer to omit an explicit return statement, specifying instead that the last evaluated expression is the return value of the subroutine.
About this result
This page is automatically generated and may contain information that is not correct, complete, up-to-date, or relevant to your search query. The same applies to every other page on this website. Please make sure to verify the information with EPFL's official sources.