+ 1
What actually return do?
4 Antworten
+ 6
C++ wise, 'return' keyword is used to transfer a specific value out from a function back to wherever the function is called.
E.g.
string star_wars ()
{
return "jedi";
}
int main()
{
cout << star_wars();
return 0;
}
// outputs "jedi"
+ 4
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 codethat called the function.
Source: Wikipedia.
(checked and it is explained just fine)
+ 3
there are many uses of return the most common use is it is the output of the function. the function acts like the value it returns
var a=6. a is 6
var b=a. b is 6
var c=increase(a) c is 7
if function increase(a){
return a++;
}
0
It save any value assigned to the function name.
For example.
Int func() {
Int x =4, y=2, z=0;
z=x-y;
return z;
}
So now the value of z which is 2 is place in func(). Whenever you call this function in main, and print it out will produce 2.
cout<<func() ;