main函数的三个参数
2018-01-01 00:54
337 查看
函数原型:
int main( int argc, char *argv[], char *envp[] )The main function marks the beginning and end of program execution. A C or C++ program must have one function named main. If your code adheres to the Unicode programming model, you can use the wide-character version of main, which is wmain.
函数参数:
argcAn integer specifying how many arguments are passed to the program from the command line. Because the program name is considered an argument, argc is at least 1.
argv
An array of null-terminated strings. It can be declared as an array of pointers to char (char *argv[ ] or wchar_t *argv[ ] for wmain) or as a pointer to pointers to char (char **argv or wchar_t **argv for wmain). The first string (argv[0]) is the program name, and each following string is an argument passed to the program from th 4000 e command line. The last pointer (argv[argc]) is NULL.
envp
A pointer to an array of environment strings. It can be declared as an array of pointers to char (char *envp[ ]) or as a pointer to pointers to char (char **envp). If your program uses wmain instead of main, use the wchar_t data type instead of char. The end of the array is indicated by a NULL pointer. The environment block passed to main and wmain is a “frozen” copy of the current environment. If you subsequently change the environment via a call to putenv or _wputenv, the current environment (as returned by getenv/_wgetenv and the _environ/ _wenviron variable) will change, but the block pointed to by envp will not change. This argument is ANSI compatible in C, but not in C++.
三个参数:
argc表示有多少个命令行参数,第一个就是执行程序名,所以argc最少为1。
argv是具体的参数。
envp是系统的环境变量,很少有介绍的。“名称=值”的形式,以NULL结束。
其他:
*envp: 安符串数组。envp[] 的每一个元素都包含ENVVAR=value形式的字符串。其中ENVVAR为环境变量如PATH或87。value 为ENVVAR的对应值如C:\DOS, C:\TURBOC(对于PATH) 或YES(对于87)。 Turbo C2.0启动时总是把这三个参数传递给main()函数, 可以在用户程序中说明(或不说明)它们, 如果说明了部分(或全部)参数, 它们就成为main()子程序的局部变量。
Test Code:
int main( int argc, char *argv[], char *envp[] ) { for ( int i = 0; i < argc; ++i ) { printf( "%d : %s \n", i, argv[ i ] ); } for( int i = 0; envp[i] != NULL; ++i ) { printf( "%d : %s \n", i, envp[ i ] ); } return 0; }
< 部分摘自 CSDN>
相关文章推荐
- 关于main函数的三个参数
- main函数的三个参数
- 【C语言】【面试题】使用main函数的参数,实现一个整数计算机,程序可以接受三个参数
- 关于main函数的三个参数
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。
- 【C语言】【面试题】使用main函数的参数,实现一个整数计算机,程序可以接受三个参数
- 见过有三个参数的main函数吗——main(int argc, char *argv[], char *env[])
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。
- main函数的三个参数
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。
- 关于main函数的三个参数
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。
- 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。
- 传递给main函数的三个参数
- 学习笔记_JavaSE_16_list的三个子类、泛型、增强for、静态导入、可变参数
- TCP/IP(1)——TCP/IP协议的四个层次,工作原理和三个参数
- VS+OpenCV使用自带samples代码时,main函数参数为int argc,char*argv的问题