0

What is return? When and why do we need to use this?

26th May 2018, 9:19 PM
Mr Thaw
Mr Thaw - avatar
3 Respuestas
+ 7
return is used to return somthing back to the method you called it from
26th May 2018, 10:34 PM
D_Stark
D_Stark - avatar
+ 1
A function with a return statement returns some sort of value that can be used by the thing calling the function, in statically typed languages (C++, Java, C# ect) you need to specify what type that will be normally near the function name, example in C++ include <iostream> using namespace std; int add(int num) { //int at the start tells us the function will return an int return num + 2; // anything that uses this function variable, another function ect will receive the result of num + 2 } int main() { cout << add(3) << "\n"; // add gives the result of num (3) + 2 to cout which then prints it out return 0; }
26th May 2018, 10:37 PM
TurtleShell
TurtleShell - avatar
+ 1
to return something or to quit
28th May 2018, 3:38 AM
Kazu