0 like 0 dislike
44 views
in Computer Science by (1.0m points)
What is return statement?

1 Answer

0 like 0 dislike
by (1.0m points)
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after where the subroutine was called, known as its return address. The return address is saved, usually on the process's call stack, as part of the operation of making the subroutine call. Return statements in many languages allow a function to specify a return value to be passed back to the code that called the function.

Overview

In 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. 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.

In other cases a Null value is returned if there is no explicit return statement: in Python, the value None is returned when the return statement is omitted, while in JavaScript the value undefined is returned.

In Windows PowerShell all evaluated expressions which are not captured (e.g., assigned to a variable, cast to void or piped to $null) are returned from the subroutine as elements in an array, or as a single object in the case that only one object has not been captured.

In Perl, a return value or values of a subroutine can depend on the context in which it was called. The most fundamental distinction is a scalar context where the calling code expects one value, a list context where the calling code expects a list of values and a void context where the calling code doesn't expect any return value at all. A subroutine can check the context using the wantarray function. A special syntax of return without arguments is used to return an undefined value in scalar context and an empty list in list context. The scalar context can be further divided into Boolean, number, string, and various reference types contexts. Also, a context-sensitive object can be returned using a contextual return sequence, with lazy evaluation of scalar values.

Related questions

0 like 0 dislike
1 answer 35 views
0 like 0 dislike
1 answer 35 views
asked Feb 14, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
1 answer 38 views
asked Feb 14, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
1 answer 41 views
0 like 0 dislike
1 answer 29 views
asked Feb 13, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
0 answers 49 views
asked Feb 13, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
1 answer 21 views
0 like 0 dislike
1 answer 27 views
asked Feb 11, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
1 answer 38 views
asked Feb 11, 2019 in Computer Science by danish (1.0m points)
0 like 0 dislike
1 answer 29 views
Welcome to Free Homework Help, where you can ask questions and receive answers from other members of the community. Anybody can ask a question. Anybody can answer. The best answers are voted up and rise to the top. Join them; it only takes a minute: School, College, University, Academy Free Homework Help

19.4k questions

18.3k answers

8.7k comments

3.3k users

Free Hit Counters
...