Why return 0; is normally used in basic program.What is that can any one explain the use | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why return 0; is normally used in basic program.What is that can any one explain the use

8th Oct 2017, 2:38 AM
Sabari
Sabari - avatar
3 Answers
+ 1
Really, nothing would happen, unless you were using a script that ran multiple C++ files, one after another. A "0" return just tells the OS that the program ended without any errors, and a non-zero return just means some sort of error occured, but it really doesn't change much.
8th Oct 2017, 3:01 AM
LunarCoffee
LunarCoffee - avatar
0
As you probably know, every C++ program must have a "main()" function. For example in the code below: int main() { return 0; } Now, look at the "int" in front of the "main()." This is the return type of the "main()" method (if you haven't learned about methods/functions... then after you do, you will probably understand. The return type is the type of value the function will return to it's call(s), as the name suggests. The "return 0;" is just to end the program properly, as without it, the "main()" function is improperly defined, and will raise an error, because it doesn't return the int it is supposed to return. Hopefully this made sense, if not now, later. Happy coding! 😁
8th Oct 2017, 2:54 AM
LunarCoffee
LunarCoffee - avatar
0
I use return 1 instead of return 0 what will happpen
8th Oct 2017, 2:58 AM
Sabari
Sabari - avatar