Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
why we use int main() and Void main()

and why we return 0 in int main()


i am in confussion.


Please tell me about in detail.
Posted
Comments
joshrduncan2012 11-Jul-14 12:42pm    
I strongly suggest researching the difference between the return value requirements for int and void.

1 solution

Both are acceptable. The return value it the ExitCode which is returned to the OS when application is already terminated. Exit code conventions are application-specific, not based on any standard. Usually, 0 is considered as "no problem", and other values can be used to indicate some problems encountered during application execution. A parent process (for example some your application which started the application in question or a batch file where it is called errorlevel) can examine exit code after the process is terminated and do something with this value.

These days, this feature is not used often, because it is pretty archaic in its nature and style. I can be used in some pretty unusual techniques, when spawning a separate process is important, but working in several processes is itself not very usual, because processes are well isolated in modern OS.

Please see: http://en.wikipedia.org/wiki/Exit_code[^].

—SA
 
Share this answer
 
v5
Comments
nv3 11-Jul-14 13:12pm    
5ed.
Sergey Alexandrovich Kryukov 11-Jul-14 14:15pm    
Thank you.
—SA
joshrduncan2012 11-Jul-14 14:05pm    
*thumbs up* my +5
Sergey Alexandrovich Kryukov 11-Jul-14 14:15pm    
Thank you.
—SA
WuRunZhe 12-Jul-14 7:28am    
Nice answer.

But, If program have "void main()" function, what is the expected ExitCode?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900