0
What does return means and how does it work?
If anyone know please help
3 ответов
+ 2
return is a keyword which returns the control flow to the area where the function is called. It can also return some value with it. Like, return xyz;
which can be used like, abc = func();
Now, abc stores the value of xyz.
0
It is exactly as it sounds, the 'return' statement returns a value. In c++, functions have to return a value, it is a rule. The only exception are functions of type void, void functions by definition do not return a value.
The function int main is the main function, meaning the program starts in the function int main. If inside the body of the function int main, there is a call to another function, say int mult, then the function mult will return a value for the main function to use.
There are many uses for return, but the basic idea is that functions that are not type void must return a value to the main function.
Since int main is a function of type int, it too must return a value, so it returns a value as well. Typically you will see return 0; at the end of a program, that is a way for the program to stop execution successfully. If the program does not reach that statement, that usually means something bad happened.
0
Lakshay Mittal brings up a good point, here is an example of what he describes.
https://code.sololearn.com/cbsvCK5DM8kS/#cpp