Use of return 0 ;?

why do we write return 0 ; at the end of the main function?

Hi Alankrit
In C and C++ programs the main function is of type int and therefore it should return an integer value. The return value of the main function is considered the “Exit Status” of the application. On most operating systems returning 0 is a success status like saying “The program worked fine”.

Hope it helps
Give a like if you’re satisfied :slight_smile:

but the code runs fine even if we doesn’t include return 0 ;
and also why do we use void with the main function in C while int in C++ ?

Note that on C,C++ compilers and C99 onwards compilers if you skip return statement in your main function, compiler would add a return 0 or return EXIT_SUCCESS for you.

In C you may use void main() or int main(). But in C++ you must use int main(). It’s kind of predefined in the language.

Hope it helps

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.