0

What is the use of return o

11th Jun 2019, 11:47 AM
John J Mumba
John J Mumba - avatar
2 ответов
0
int main() is a function that returns an integer value (int). In main (), it doesn't matter , but in the functions you create, you can return a value. For example: #include <iostream> using namespace std; int myfunc (int x){ x++; return x; } int main() { cout << myfunc (5); return 0; } //output: 6
11th Jun 2019, 11:58 AM
Maxim Balakirev
Maxim Balakirev - avatar
0
See the return 0 is used in the main which we write it as int main ( ) and if you have the concepts of function you will notice that its a function named as main . And if you can notice this is the first and last function that the program encounters with despite all function prototypes and while function it should return something (it can be void , it can be int or any other data types) and there are some compilers that allows you to use void main in which you don't have to write return 0 but its a bad habit since the return 0 is the last statement the program is going to encounter and while compilation if compiler sees that yes the program is returning 0 that means all the former statements are compiled correctly and the program is ready for execution So the main thing is it usually represents that if the is returning 0 at last then it doesn't have any errors.
11th Jun 2019, 12:30 PM
Sahil Bhakat
Sahil Bhakat - avatar