This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return 0 in main() function

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1061
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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%
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic