argc AND argv[0]

Posted defoliate

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了argc AND argv[0]相关的知识,希望对你有一定的参考价值。

reference: http://crasseux.com/books/ctutorial/argc-and-argv.html

argc stands for argument counts.

the "v" of argv[] stands for vector, and argv stands for the specific parameter when you input in command. We could test them with the following code.

Notice: when we execute the following program, it should be executable file. e.g. it should be ./a a b c, not gcc -o ab a.cpp

#include <stdio.h>

int main (int argc, char *argv[])
{
  int count;

  printf ("This program was called with "%s".
",argv[0]);

  if (argc > 1)
    {
      for (count = 1; count < argc; count++)
    {
      printf("argv[%d] = %s
", count, argv[count]);
    }
    }
  else
    {
      printf("The command had no other arguments.
");
    }

  return 0;
}

 

以上是关于argc AND argv[0]的主要内容,如果未能解决你的问题,请参考以下文章

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

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

在代码中创建 argc argv [重复]

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

int main(int argc,char *argv[])与int main(int argc,char **argv)区别?

argc argv 详细解答