main
returns int
. In older versions of C you could leave out the int
and the compiler would pretend that you had said int
. In C++, if 'main' doesn't explicitly return a value, it magically returns 0. You can return three values from main
: 0, EXIT_SUCCESS, and EXIT_FAILURE. 0 is equivalent to EXIT_SUCCESS. The two named values are defined in <stdlib.h>
and if you're coding in C++ in <cstdlib>
.
The void
is a C-style declaration that a function takes no arguments. In C++ you don't need it; a function that has no arguments in its declaration takes no arguments.
In general, though, main
takes two arguments:
int main(int argc, char *argv[])
Those are the command-line arguments. argc
is the number of arguments, and argv
is an array of pointers to C-style strings that hold the arguments. The first string (argv[0]
) is the name of the program.