The main() Function

When a program begins running, the system calls the function main, which marks the entry point of the program. Every program must have one function named main. No other function in the program can be called main. A main function has one of two forms:

C int main (void) block_statement

C++int main ( )block_statement

int main (int argc, char ** argv)block_statement

The argument argc is the number of command-line arguments passed to the program. The argument argv is a pointer to an array of strings, where argv[0] is the name you used to run your program from the command-line, argv[1] the first argument that you passed to your program, argv[2] the second argument, and so on.

By default, main has the storage class extern.

C++You cannot declare main as inline or static. You cannot call main from within a program or take the address of main. You cannot overload this function.

Related References

IBM Copyright 2003