This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 1006
    
    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%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Return 0 in main() function
 
Similar Threads
Exit Sub in java?
Getting a return value from a function and using it another fuction
why there is a compile time error
How to send the contents of a screen in an email
Oracle select in view question (String function ? )