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.

m a i n ( ) 给main()函数传递两个参数 i n t int a r g c c h a r a r g v [ ] argc和char* argv[]
a r g c argc:表示命令行参数的个数,不许要用户传递,它会根据用户从命令行输入的参数个数,自动确定
a r g v [ ] , c h a r a r g v argv[]:存储用户从命令行传递进来的参数,它的第一个成员是用户运行的程序名字,也可写为char** argv

在这里插入图片描述

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.

发布了165 篇原创文章 · 获赞 124 · 访问量 5548

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/105310314