+ 5
Can someone please explain:
Why in C++ the main method has a return type of int and why it need to return a value? Thank you very much.
2 Réponses
+ 4
Think about using your code in a command line (e.g. in a bash or a batch script): if you call your compiled code you call the main method giving to it the arguments passed in the string parameter. The result of your code would be passed to the script to test if an error is occurred. You could pass always 0 but you would lose the functionality of the result that in case of error would stop the script.
+ 3
generally the return value of the main indicates how the programme exited. if it returns a zero then the programme returned normally and a non-zero return signifies an abnormal exit