主函数的形参

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

//int argc表示传递参数的个数 ;eg:gcc -o hello hello.c(4个参数"gcc", "-o", "hello", "hello.c")

//char*argv[]是指针数组,表示参数具体内容;char*argv[]={"gcc", "-o", "hello", "hello.c"}

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

{

  if(argc<3)

  {

    printf("缺少参数 ");

    return -1;

  }

//在循环内部定义需要使用c99编译器

  for(int i=0;i<argc;i++)

  {

    printf("%s ",argv[i]);

  }    

  /*外部定义

  int i;

  for(i=0;i<argc;i++)

  {

    printf("%s ",argv[i]);

  }*/

//gcc编译

 

 

 

  return EXIT_SUCCESS;

}

原文地址:https://www.cnblogs.com/wanghong19991213/p/13591189.html