• 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: 1108
7
  • 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%
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!