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

Command Line Arguments_第1张图片

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.

你可能感兴趣的:(sanfoundry)