Saturday, May 12, 2012

Why not to use void main

In college, while using turbo c, we learn to use "void main()". But this is against c++ standard. Actually this shouldn't compile. Main function must return a int value. Main function should be declared like "Int main()". And at the end "return 0" may be added to indicate that function executed successfully. It may return 1 in order to indicate that some error has occurred. This is also referred as Exit Status. It can be EXIT_SUCCESS (traditionally 0) and EXIT_FAILURE. If return is not provided by programmer, it will return 0 by default.  For other exit statuses you may have a look in stdlib.h(cstdlib).

No comments:

Post a Comment