A very common doubt of a beginner is, “For what is the return 0 at the end of main function used?”
Here we shall discuss what the return 0 signifies. Let us first know that the main() can be declared in different formats.
And yes you can define with other existing data types and all those are accepted by C compiler. Returning a value makes sense as each function need to return some value that belongs to the data type of that function. So we declare a return statement at the end of main() function to return a value that belongs to data type main() is defined with.
And so we actually return ‘0’ at the end of int main(). Even main() is considered as int main() as default and hence you can return integer values at the end of main(). And yes you could also return any number other than ‘0’ for int main() and that would work perfect.
However it is not any compulsion of defining return statement as most of the compilers by default return ‘0’ value at the end of main() function.
A void main() does not return any value, since data type ‘void’ mean to have no value in it.
Edit: (From the comment by ythej)
Returning 0 for main function signifies that program is executed without errors. And returning non zero values implies program has some errors. However in our local machines, this does not produce any error for returning any value from main function. But when we submit some code on online compilers, they produce a run time error(NZEC) signifying program has got some error at the time of execution(error according to compiler). NZEC itself abbreviates for Non-Zero-Exit-Code, implies main returns a non zero value.