+ 2
Why return 0 is used
3 Antworten
+ 9
In C++ programs the main function is of type int and therefore it should return an integer value. Thereturn value of the main function is considered the "Exit Status" of the application. On most operating systems returning 0 is a success status like saying "The program worked fine".
It is actually up to you to determine which return value you want to signal that your program has run successfully. In other situations where your program just crashes due to faulty pointers, the value will not be 0.
+ 4
The return value of main function is passed to the caller of the program in the system shell. There is a convention to interpret 0 return value as successful termination of the program, and any nonzero value as termination with an error.
This may be used in the OS shell scripts to know if the task was completed successfully.
+ 1
thanks a lot