What is the correct (most efficient) way to define the main()
function in C and C++ — int main()
or void main()
— and why? And how about the arguments?
If int main()
then return 1
or return 0
?
There are numerous duplicates of this question, including:
- What are the valid signatures for C’s
main()
function? - The return type of
main()
function - Difference between
void main()
andint main()
? main()
‘s signature in C++- What is the proper declaration of
main()
? — For C++, with a very good answer indeed. - Styles of
main()
functions in C - Return type of
main()
method in C int main()
vsvoid main()
in C
Related:
- C++ —
int main(int argc, char **argv)
- C++ —
int main(int argc, char *argv[])
- Is
char *envp[]
as a third argument tomain()
portable? - Must the
int main()
function return a value in all compilers? - Why is the type of the
main()
function in C and C++ left to the user to define? - Why does
int main(){}
compile? - Legal definitions of
main()
in C++14?