0
Difference
Between "int main()" and "void main()"
4 ответов
+ 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()
+ 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