+ 9
Differences between int main() and void main()
What is the most efficient way to define the main() function in C++ : int main() or void main() and why? I used to write void main() for then not to write return 0;.. is there any difference except the return type?
4 Respuestas
+ 12
yes there are differences, as developers of C++ said there is no such a thing as void main(). It's smth created by Microsoft and only Microsoft's compiler can handle that. Every other compiler (e.g. gcc) are working only with int main().
So, in my opinion it's good practice to only use int main() in order to avoid conflicts with other compilers.
+ 3
This question already appeared today, so here is just my copied answer:
Void means something line "no return value", while int has to return integer. It is always bad to use void main(), because only some compilers support it, so it's possible you will get an error just because you use void main().
When you use int main(), it needs to return a value (return 0 means "program executed successfuly"). In some compilers return 0 is not necessarry, because they will add it to the end if you didn't do that.
So always use 'int main()' with 'return 0' statement in the end.
+ 2
int main means that the main returns an integer value as while using function we use void that implies that the function does not return any value similar is the case with main.
0
simple answer:
int returns a value
void doesn't return a value