C++ main函数
All C++ programs must have a main
function. If you try to compile a C++ .exe project without a main function, the compiler will raise an error. (Dynamic-link libraries and static libraries don't have a main
function.) The main
function is where your source code begins execution, but before a program enters the main
function, all static class members without explicit initializers are set to zero. In Microsoft C++, global static objects are also initialized before entry to main
. Several restrictions apply to the main
function that do not apply to any other C++ functions. The main
function:
- Cannot be overloaded (see Function Overloading).
- Cannot be declared as inline.
- Cannot be declared as static.
- Cannot have its address taken.
- Cannot be called.
所有C++程序都必须含有一个main函数。
argc
An integer that contains the count of arguments that follow in argv. The argc parameter is always greater than or equal to 1.
argv
An array of null-terminated strings representing command-line arguments entered by the user of the program. By convention, argv[0]
is the command with which the program is invoked, argv[1]
is the first command-line argument, and so on, until argv[argc]
, which is always NULL. See Customizing Command Line Processing for information on suppressing command-line processing.
The first command-line argument is always argv[1]
and the last one is argv[argc - 1]
.
第一个参数argc:参数个数
第二个参数argv:参数组