First, speaking of C, return type of main()
should be int
.
This is from the C language standard:
5.1.2.2.1 Program startup
1. The function called at program startup is named main
. The implementation declares no
prototype for this function. It shall be defined with a return type of int
and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc
and argv
, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.
Second, char *argv[]
is there to allow for multiple command line arguments. Although char *argv[0]
looks strange but valid, it is common to leave to your command line argument parser dealing with this programmatically.
Here is a code example demonstrating that char *argv[0]
does not affect command line argument parsing:
#include <stdio.h>
int main(int argc, char *argv[0])
{
for (int i = 0; i < argc; i++)
printf("%s\n", argv[i]);
return 0;
}