Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts

    Could someone please explain what return 0 means in English?

    I just had the worst experience with regard to StackOverflow. The people there are absolutely rude.

    Could someone please explain what return 0 means in English?

    I'm just beginning in C and C++, and this is something I see a lot. What exactly does it mean?


    Thanks!
    Last edited by Microsuck; 01-02-2012 at 02:23 AM.
    PHP Code:
    <?php echo "Microsuck says hi!"?>

  • #2
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    it basicly means that the program exits when
    Code:
    return 0
    is run (I'm pretty sure)

  • #3
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by melloorr View Post
    it basicly means that the program exits when
    Code:
    return 0
    is run (I'm pretty sure)
    Thanks for answering. But that doesn't make sense to me.

    I apologise to everyone if I'm coming off as rude myself, that stack overflow experience really pissed me off.
    PHP Code:
    <?php echo "Microsuck says hi!"?>

  • #4
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Well, I have only done a tiny bit of C++ but, say you had Main():

    Code:
    int main()
    {
    	int num1 = 10;
    	int num2 = 23;
    	int sum;
     
    	sum = num1 + num2;
     
    	return 0;  //program exits here, 0 goes to operating system
    }
    That may not be the right syntax or anything, but when it reaches return 0, the 0 tells it to exit the program. If it wanted to keep running, it could say return sum; or something.

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    What you return from a function depends upon what return type you have defined for that function. If you are returning 0 then your return type is likely integer which is of course the return type of your main function. In regards to the main function return 0 means to exit the program cleanly without errors. If you were to return a 1 it would indicate an error with the program. For custom defined functions that return value can be defined to mean what you need it to be.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • Users who have thanked Spookster for this post:

    Microsuck (01-02-2012)

  • #6
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Spookster View Post
    What you return from a function depends upon what return type you have defined for that function. If you are returning 0 then your return type is likely integer which is of course the return type of your main function. In regards to the main function return 0 means to exit the program cleanly without errors. If you were to return a 1 it would indicate an error with the program. For custom defined functions that return value can be defined to mean what you need it to be.
    Thanks Spookster! You're a pro!
    PHP Code:
    <?php echo "Microsuck says hi!"?>

  • #7
    New Coder
    Join Date
    Nov 2011
    Location
    Pakistan
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts
    in beginning return 0 in main() function means to terminate the programe, the main() function will be terminated.
    While in some other function, function of some data type, return is used to return the give back some value.
    in any of the function , after return statement no statement will b execute.

  • #8
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I read all the replies.all of them correct.but in addition return 0 is something that give back 0 to main() and 0 in C++ means true.after that,when main() get something true it understand that everything in program is true so the program can be run.

  • #9
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by sabsa View Post
    I read all the replies.all of them correct.but in addition return 0 is something that give back 0 to main() and 0 in C++ means true.after that,when main() get something true it understand that everything in program is true so the program can be run.
    0 doesn't mean true, it means successful, but I see what you mean. Thanks for the help!
    PHP Code:
    <?php echo "Microsuck says hi!"?>

  • #10
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    your welcome and thanks for correcting.
    Last edited by sabsa; 01-07-2012 at 04:01 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •