In C/C++ language, main function comes in different flavors as shown below:
int main(); int main(int argc, char **argv); int main(int argc, char **argv, char **envp); int main(int argc, char **argv, char **envp, char **apple);
What is the signature of main specified in the language standard ?
Solution:
You may want to refer to page-12 in the C99 standard of C language, or just read below:
The return type of main function should be an int and it be defined in with either no parameters, as below (any of the two declarations):
int main(); int main(void);
or 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) as shown below (both declarations are equivalent):
int main(int argc, char *argv[]); int main(int argc, char **argv);
The two parameters to main function should follow the below rules:
Other platform-dependent signatures of main function are also allowed by the C and C++ standards, except that in C++ the return type must always be int.
Signature of main on Windows & Unix:
Unix (though not POSIX.1) and Microsoft Windows have a third argument giving the program’s environment (the environment variables), otherwise accessible through getenv in stdlib.h:
int main(int argc, char **argv, char **envp);
Signature of main on MAC OS X
Mac OS X and Darwin have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary:
int main(int argc, char **argv, char **envp, char **apple);
The value returned from main function becomes the exit status of the program.
The C standard only ascribes specific meaning to two values: EXIT_SUCCESS (traditionally 0) and EXIT_FAILURE (non-zero).