Difference | Sololearn: Learn to code for FREE!

0

Difference

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

c

11/19/2019 3:47:25 PM

MD Tanveer Hossain Nihal

4 Answers

New Answer

+5

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()

+2

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

+1

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

+1

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