main()函数参数的一般形式: int main(int argc, char *argv[])

int argc用来表示参数的数量,argv[]数组是用来存放参数的值;

但是在linux下的gcc编译中传参的时候会出现一点问题,直接上代码好了:

1  #include<stdio.h>
2  int main(int argc, char *argv[])
3  {
4      printf("the first argc is %s\n",argv[0]);
5      printf("the second argc is %s\n",argv[1]);
6      printf("the third argc is %s\n",argv[2]);
7      printf("the fouth argc is %s\n",argv[3]);
8  }

结果如下:

【C】关于main()函数参数的问题;

结果把./a.out也作为了一个参数也传了进去,所以第一参数会被认为是./a.out。我们在处理参数的时候需要注意这一点了!

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2022-01-04
  • 2022-12-23
  • 2022-01-10
  • 2021-08-20
  • 2022-01-04
猜你喜欢
  • 2021-07-17
  • 2021-10-02
  • 2021-08-17
  • 2021-12-20
  • 2021-12-04
相关资源
相似解决方案