main函數形參argc和argv解析
阿新 • • 發佈:2017-08-08
執行 order col pre 4.4 ont + - printf std
測試環境:ubuntu 16.0
編譯器: g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 (查看版本指令:g++ --version)
以下為測試代碼:
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(int argc, char* argv[]) 5 { 6 int count = 0; 7 8 //獲取終端輸入指令 9 for( ; count < argc; ++ count) 10 {11 printf("%s\n", argc[count]); 12 } 13 printf("has %d orders\n", count); 14 15 return 0; 16 }
執行結果:
[email protected]:~/projects/proj$ ./server hello reacher
./server
hello
reacher
has 3 orders
得出結論:
argc 存儲著統計終端輸入指令總數
argv 存儲輸入的指令
main函數形參argc和argv解析