Why we use return 0; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why we use return 0;

9th Nov 2019, 12:53 PM
Prasad
14 Answers
+ 3
Because your function type is int.If you use void, it will simply be return;
9th Nov 2019, 1:03 PM
Jayesh Mishra
Jayesh Mishra - avatar
+ 8
Because that is the return data type as prescribed by the standard. See: https://isocpp.org/std/the-standard
9th Nov 2019, 1:20 PM
jay
jay - avatar
+ 7
In c++, A return 0 for main() means program executed normally.... And it can't have a return type other than int...
9th Nov 2019, 1:09 PM
Saurabh B
Saurabh B - avatar
+ 4
The C main function has a return value of type integer, to give the operating system a feedback about the program execution. As a convention a zero return value indicates, that the program execution was successful.
9th Nov 2019, 3:23 PM
Michael
Michael - avatar
+ 2
For normal functions any valid data type... Either built in like int, float, char, string or user defined like a class can be return type
9th Nov 2019, 1:11 PM
Saurabh B
Saurabh B - avatar
+ 2
basically your main function is exiting with a status code. 0 as return indicates your program succeeded, other than 0 means it exited with an Error .
10th Nov 2019, 1:07 PM
Anushka Mehta
+ 1
If I use char,string type variable which return type can I use?
9th Nov 2019, 1:06 PM
Prasad
+ 1
It's not the variable, but function type.
9th Nov 2019, 1:08 PM
Jayesh Mishra
Jayesh Mishra - avatar
+ 1
Why it can't have a return type other than int? Bro Saurabh B
9th Nov 2019, 1:15 PM
Prasad
+ 1
See.. It has standard return type int predefined whether u write it as int main() or just write main()... It is already predefined... Other return type gives error
9th Nov 2019, 1:23 PM
Saurabh B
Saurabh B - avatar
+ 1
To tell the compiler that our code ends here
10th Nov 2019, 2:22 PM
Alok Yadav
Alok Yadav - avatar
0
It depends upon which type of function you make. If you make a function of type int or anything else except void, you are to return something. In case of void, you do not need to return anything.
10th Nov 2019, 11:58 AM
Zain Basharat Ali
Zain Basharat Ali - avatar
0
To return a value of data type
10th Nov 2019, 6:14 PM
Sakshi Pachkhande
Sakshi Pachkhande - avatar
0
Because thats the end of your data and program. Some programs do not need return 0; But instead use system("Pause"); to pause your program
11th Nov 2019, 11:48 AM
John Dayos
John Dayos - avatar