...

View Full Version : Resolved Could someone please explain what return 0 means in English?



Microsuck
01-02-2012, 01:45 AM
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!

melloorr
01-02-2012, 02:01 AM
it basicly means that the program exits when
return 0 is run (I'm pretty sure)

Microsuck
01-02-2012, 02:06 AM
it basicly means that the program exits when
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.

melloorr
01-02-2012, 02:21 AM
Well, I have only done a tiny bit of C++ but, say you had Main():


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.

Spookster
01-02-2012, 07:46 AM
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.

Microsuck
01-02-2012, 11:03 PM
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!

Adeel.Rekhi
01-03-2012, 04:03 PM
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.

sabsa
01-06-2012, 12:13 PM
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.

Microsuck
01-06-2012, 04:00 PM
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!

sabsa
01-07-2012, 04:48 PM
your welcome and thanks for correcting.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum