0

What is return 0;

12th Dec 2016, 3:36 PM
dalina
6 Answers
+ 1
return 0 in the main function is a kind of answer To the computer saying that everthing is allright
12th Dec 2016, 3:44 PM
Mehdi Bouzidi
Mehdi Bouzidi - avatar
+ 1
when the function is of either int or any other data type then it needs something to return.. I.e. if u say.. • int main() {... .. .. return 0; } but if it was like • void main() {.. .. } In the second function it is of type void, so here the function need not to return any value.
12th Dec 2016, 4:10 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
it means void.. return 0 means it will not return any value
12th Dec 2016, 7:28 PM
Sumit Yadav
Sumit Yadav - avatar
0
All applications exit with a value to the Operating Sýstem, and since int main() is the place where the application *should* exit, then it *should* return a value to the OS in order to say what state it (tha app) exited in. As already mentioned a zero will say that all is fine. But you can exit the application from other functions than main(), but it isn't suggested unless it needs to. But you use the word exit(1 /*for example*/); to that. That would have made the same (to the OS) as return(1); from main(). Another value than 0 can say that it exited with an error, and what those error codes are and stand for, you'll have to lookup yourself, but you can incorporate it in this was. Also a return(0); from another function than main can be interpreted as a bool by the calling expression. In other words even if you return a whole number (an int) it can be applied as it returned a bool - or be confused thereof, for the same reason. I am not a clear person.
12th Dec 2016, 5:06 PM
Anderz Lindberg
Anderz Lindberg - avatar
0
return 0 returns a value, as any other value, so to claim otherwise is to lie. just a comment to a post above.
12th Dec 2016, 7:31 PM
Anderz Lindberg
Anderz Lindberg - avatar
0
Regarding Khan's post: I'd like to add that it is perfectly legal to return from a void-function. It just doesn't return a value. The return statement cannot include a return type (other than void, which is none) - in such cases - so you just use: return; In short: return returns the return type to the calling system, in the case of main() the system is the Operating System, otherwise it would normally be another calling function, for example main() calling another function that is of type void/int/... and returns exactly that (type) os->int/void main->program logic->program end->return val/[or nothing];->leave program control flow to the caller, with that value.
13th Dec 2016, 7:52 AM
Anderz Lindberg
Anderz Lindberg - avatar