What happens if main does not return 0?

Modified on Sun, 21 Feb 2021 at 07:47 PM

If main returns a non-zero value you will get a Run Time Error. However, with a C++ compiler this should not happen
as long as you (a) declare main to return int, and (b) do not explicitly return a non-zero value. If you declare main to have a non-int return type you should get a compile error. It never hurts to have an explicit return 0 at the end of main, though.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article