hello.c
#include <stdio.h> int main(int argv, char* argc[]) { printf("hello word!\n"); return 0; }
&& direct role in running the compiled for the command connection
gcc hello.c -o main.out && ./main.out
Then run to see the return parameters
echo $?
argv role:
main.c file code
#include <stdio.h> int main(int argv, char* argc[]) { printf("argv is %d\n", argv); return 0; }
Compile and then run the first file
[root@lyy les3]# gcc main.c -o m2.out [root@lyy les3]# ls m2.out main.c main.out [root@lyy les3]# ./m2.out -l -a argv is 3 [root@lyy les3]# ./m2.out -l argv is 2
argc
main.c Code:
#include <stdio.h> int main(int argv, char* argc[]) { printf("argv is %d\n", argv); int i; for(i=0;i<argv;i++) { printf("argc[%d] is %s\n",i,argc[i]); } return 0; }
Compile and run the add parameters
[root@lyy les3]# gcc main.c -o m3.out [root@lyy les3]# ls m2.out m3.out main.c main.out [root@lyy les3]# ./m3.out -l -a asdfasf fdsaf argv is 5 argc[0] is ./m3.out argc[1] is -l argc[2] is -a argc[3] is asdfasf argc[4] is fdsaf