C Language Learning 011: main Function with parameters, language learning 011
Directly Add code
1 # include <stdio. h> 2 3 int main (int argc, char * argv []) {4 printf ("% I \ n", argc); 5 int I; 6 for (I = 0; I <argc; I ++) {7 printf ("% s \ n", argv [I]); 8} 9 10 return 0; 11}
In the above main method, the first parameter argc represents the number of elements in the array, and the second parameter * argv represents the parameter array, that is, argc represents the length of * argv; interestingly, * the first element of argv is the program name.
The parameters must be separated by spaces. Otherwise, the parameters will be connected to each other.
At the same time, the program cannot contain the main function without parameters and the main function with parameters at the same time. During compilation, a prompt will be prompted to redefine the main function, as shown in