Wednesday 16 November 2011

Should main() always return a value? in C programming

Should main() always return a value?

Your main() does not always have to return a value, because the calling function, which is usually COMMAND.COM, does not care much about return values. Occasionally, your program could be in a batch file that checks for a return code in the DOS errorLevel symbol. Therefore, return values from main() are purely up to you, but it is always good to return a value to the caller just in case.

Your main() can return void (or have no return statement) without problems.

Cross Reference:

XIV.11: Should programs always include a prototype for main()?

No comments:

Post a Comment