Reputation: 113
As per the current standard and cppreference these two are the correct way to define the main()
function. I know what the parameters mean in either definition, and am not seeking clarifications on that aspect. What I'd like to understand is:
int main (void)
v/s int main (int argc, char *argv[])
.gcc
and clang
) at all?int main (void)
when the program doesn't expect command line arguments and int main (int argc, char *argv[])
when it does?Upvotes: 1
Views: 807
Reputation: 416
I think you can get a good answer here. Reading this article, my answers to your questions are:
int main (int argc, char *argv[])
whenever you need to access the program's arguments;int main (void)
whenever your program does not need to access the arguments. This way, it is clear for other people that your program do not use them. In future, if you need to access the program's arguments, changing the syntax of the main()
function is not that hard.Upvotes: 4