View Full Version : Another C++ question...
Bmxpunk86pl
12-30-01, 05:45 PM
Ok what is the return 0; thing. I m reading a guide on C++ but i dont understand what it says. THis is what it says "The return instruction makes the main() function to finish and return the code that the instruction is followed by, in this case 0. This it is most usual way to terminate a program that has not found any errors during its execution. As you will see in coming examples, all C++ programs end with a sentence similar to this. " I dont quite understand that so can anyone explain in their own words please?
tHanKs
XprincoX
12-31-01, 01:40 AM
ok it just basically follow the principle that every function that has a declared type NEEDS return a value of that type. So lets say u declare main like:
int main()
So the function will need a return value, an int in this case when the function returns. So by design, the most common return is return 0. This why alotta ppl just make main a void so there is no return type. :D
Heres a more indepth discussion: http://www.cplusplus.com/doc/tutorial/tut2-2.html
When you are programming in a proper way, you'd be ending you're functions with a return line, so the calling function knows what the execution status is, or maybe get a variable returned.
When you return from the main function, you will end the program. This is just proper etiquette, and the OS will read the return value (0) and know that the program executed fine. If you were to return a 1, the OS might do something like launch a crash screen.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.