Two valid versions of main() exist in C++:
int main() // version 1
int main(int argc, char **argv) // version 2
But both overloads cannot coexist at the same time. Why not? (Potential use case: while running the program from the terminal, if no arguments are passed the first version is called, otherwise the second version is.)
Does the compiler perform a special check to allow just one version per binary?
§3.6.1/2 (C++03) says
You can use either of them. Both are standard compliant.
Also, since
char *argv[]is equivalent tochar **argv, replacingchar *argv[]withchar **argvdoesn’t make any difference.No. Both versions cannot co-exist at the same time. One program can have exactly one
mainfunction. Which one, depends on your choice. If you want to process command-line argument, then you’ve to choose the second version, or else first version is enough. Also note that if you use second version, and don’t pass any command line argument, then there is no harm in it. It will not cause any error. You just have to interpretargcandargvaccordingly, and based on their value, you’ve to write the logic and the flow of your program.