Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What does it mean to write int argc, char*argv as main function parameters in C language? What does it do?
What does it mean to write int argc, char*argv as main function parameters in C language? What does it do?

argc is the number of parameters in your main program.

argv[0] is the name of the program when you compile it and execute it.

argv[1].....are the parameters required by your main program.

Example: the following program aa.c

#include

#include

#include

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

{

printf("%d\n", argc);

printf("%s\n",argv[0]);

printf("%s\n",argv[1]);

printf("%s\n",argv[2]);

return 0;

}

Compile: gcc -o hello aa.c (that is, the compiled executable file is called hello, which is the compilation method on Linux)

Execution: hello aa bb

Result:

2

hello

aa

bb

do you understand? c is easy in fact! !