In some examples of int main() i have seen, there is always a return 0 in the end. When do you have to return a number different then zero and what number should this be? only 1? or any numer like 4,6,1000,139438493?? I am used to simpler languages like python and Im a bit comfused.
Asked
Active
Viewed 23 times
0
-
1see [this answer](http://stackoverflow.com/a/204483/624463). – cschneid Jul 23 '16 at 15:02
1 Answers
1
Depends on the operating system.
Traditionally 0 means "ok". Use -1 or 1, 2, 3 as error indicator. And check with your OS how to work with that result

datafiddler
- 1,755
- 3
- 17
- 30
-
If I ommit this step (choosing betwenn 0 and other numbers) will it return a number on its own?and if i return 0 but there is an error what will happen? – AthensIn Red Jul 23 '16 at 15:02
-
if you don't care, nothing will happen. If you allow and ignore the warning that int main() should return something defined, it's undefined what OS will see (and ignore) as the return value. – datafiddler Jul 23 '16 at 15:09
-
thank you @cschneid, I learned that it's also defined that omitting a return statement for int main() will definitely return 0. Which is a bad practice, if you really rely on that return value in your outside system, IMO ... – datafiddler Jul 25 '16 at 17:06