Command Line Arguments

The main function of C language usually contains argc and argv, which are written as follows:

int main(int argc,char *argv[])
int main(int argc,char **argv)

These two parameters are explained in detail as follows:
argc : Total number of arguments passed in from the command line
argv : *argv[] is an array of pointers, in which the stored pointers point to all command line parameters, argv [0] points to the global path of the program, argv [1] points to the first string after executing the program name in the DOS command line, and argv [2] points to the second string.

main()给main()函数传递两个参数给main()函数传递两个参数,intintint argccharargv[]argc和char* argv[]argc和char∗argv[]
argcargc:表示命令行参数的个数,不许要用户传递,它会根据用户从命令行输入的参数个数,自动确定argc:表示命令行参数的个数,不许要用户传递,它会根据用户从命令行输入的参数个数,自动确定
argv[],charargvargv[]:存储用户从命令行传递进来的参数,它的第一个成员是用户运行的程序名字,也可写为char** argvargv[]:存储用户从命令行传递进来的参数,它的第一个成员是用户运行的程序名字,也可写为char∗∗argv

Command Line Arguments

Question 3:

Explanation: All the options mentioned (./a.out, ./test, ./fun.out.out) are simply the command without any argument. A command is always stored as argument vector zero i.e., argv[0] always contain the command where as argv[1], argv[2], etc. contains the arguments to the commands, if any.

上一篇:android中遇到ERROR: Could not find method clean() for arguments这个奇葩的错误如何解决!!


下一篇:JavaScript基础之--- 手写 apply方法 的实现