终端命令行参数
On many systems, it is possible to pass arguments to main from a command line by including parameters int argc and char argv[] in the parameter list of main. Parameter argc receives the number of command-line arguments. Parameter argv is an array of strings in which the actual command-line arguments are stored. Common uses of command-line arguments include printing the arguments, passing options to a program and passing filenames to a program.
在许多系统上,可以通过在 main 的参数列表中包含参数 int argc 和 char argv[] 来从命令行向 main 传递参数。 参数 argc 接收命令行参数的数量。 参数 argv 是一个字符串数组,其中存储实际的命令行参数。命令行参数的常见用途包括打印参数、将选项传递给程序以及将文件名传递给程序。
#include <stdio.h>int main(int argc, char *argv[]) {printf("%s%d.\n","argc is ", argc);for (short index = 0