File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes C / C++ and the fly likes Return 0 in main() function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Return 0 in main() function" Watch "Return 0 in main() function" New topic
Author

Return 0 in main() function

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
If I use return 0; in main function( and define in as int main() ,of course)then where does the control is transferred after execution of that last line in the code??Isn't it absurd to use return 0 in main()..???
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1010
    
    3
Anonymous wrote:If I use return 0; in main function( and define in as int main() ,of course)then where does the control is transferred after execution of that last line in the code??Isn't it absurd to use return 0 in main()..???


The return value from the main function/method is returned to the operating system. Returning a 0 indicates no errors, by convention. IF I RECALL CORRECTLY, in bash (a Unix shell) the return value of a program is assigned to the $? variable:

myProg arg1 arg2
echo myProg returned $?

DOS/Windows does a similar thing with the %ERRORLEVEL%

myProg
echo myProg returned %ERRORLEVEL%
 
Don't get me started about those stupid light bulbs.
 
subject: Return 0 in main() function