Difference | Sololearn: Learn to code for FREE!



Between "int main()" and "void main()"


11/19/2019 3:47:25 PM

MD Tanveer Hossain Nihal

4 Answers

New Answer


First of all if you are using C language you doesn't need to add either int or void before main() just write only main() this is correct. But if you use then it will also be correct to go with void or int. So the differences are: In 'int main()' it is declared that main() is returning a int value so you have to add the statement 'return 0;' at the end of code because in this case the main() function is returning a value of int. In 'void main()' no value is returned so there is no need of 'return 0;' But the practice of writing 'int main()' is far better than writing only 'main()' or 'void main()'. because it will help you in the writing of functions So, keep going with int main()


See... https://en.cppreference.com/w/c/language/main_function


Return type. int main() function should return an integer, while void main() function doesn't return any thing.. Read about function prototypes, return types..


There's a summary about C and C++ main function valid signature (according to the standards). But none approved `void main` or just `main`. Except a little note regarding implementation in non hosted environment (embedded etc.) and Microsoft's compiler "feature" which allows `void main` wherein exit code is returned through the `exit` function call. https://stackoverflow.com/questions/2108192/what-are-the-valid-signatures-for-cs-main-function