What is the main function of C language with parameters?

The format du of the parameterized baimain function of C language is main(int argc,char* argv[]), where zhiargc is the number of parameters plus 1, argv is the parameter list, and dao starts from zhuanargv[1]. An executable file is generated after compilation. You can add parameters after the executed program. For example, if you compile a program as test.exe, you can enter during execution:
test.exe 1 firestone
here, argc is equal to 3, argv[0] Is "test.exe", argv[1] is "1", and argv[2] is "firestone".
If there is the following program:

#include <stdio.h>
void main(int argc,char *argv[])
{
    
    
printf("You've input %d parameters.\n",argc-1);
for(int i=1;i<argc;i++)printf("The No.%d is:%s\n",i,argv[i]);
}

The above input will produce the following results:
You've input 2 parameters.
The No.1 is 1
The No.2 is firestone

Guess you like

Origin blog.csdn.net/qq_42955211/article/details/112802817