aptitude 命令
C programming Command Line Arguments Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Command Line Arguments – Passing values with running programs, separate argument values, number of arguments etc.
C編程命令行參數能力問題和解答:在本節中,您將找到命令行參數的C能力問題和解答-通過運行程序傳遞值,單獨的參數值,參數數目等。
C:\TC\BIN>prg_1 includehelp.com C C++ Java
#include <stdio.h>
int main(int argc,char* argv[])
{
printf("%d",argc);
return 0;
}
4
5
6
3
5
The first argument of main argc contains the total number of arguments given by command prompt including command name, in this command total arguments are 5.
C:\ TC \ BIN> prg_1 includehelp.com C C ++ Java
4
5
6
3
5
main argc的第一個參數包含命令提示符給出的參數總數,包括命令名稱,在此命令中,參數總數為5。
C:\TC\BIN>prg_2 1,2 "Ok" "Hii" Hello , AAA
#include <stdio.h>
int main(int counter,char** arg)
{
unsigned char tally;
for(tally=0;tally< counter; tally+=1)
printf("%s|",arg[tally]);
return 0;
}
C:\TC\BIN\PRG_2.EXE|1,2|Ok|Hii|Hello|,|AAA|
ERROR: Invalid argument list.
C:\TC\BIN\PRG_2.EXE|1|,|2|Ok|Hii|Hello|,|AAA|
1,2|Ok|Hii|Hello|,|AAA|
C:\TC\BIN\PRG_2.EXE|1,2|Ok|Hii|Hello|,|AAA|
C:\ TC \ BIN> prg_2 1,2“確定”“ Hii”您好,AAA
C:\ TC \ BIN \ PRG_2.EXE | 1,2 |確定| Hii |你好|,| AAA |
錯誤:無效的參數列表。
C:\ TC \ BIN \ PRG_2.EXE | 1 |,| 2 | OK | Hii | Hello |,| AAA |
1,2 |確定| Hii |你好|,| AAA |
C:\ TC \ BIN \ PRG_2.EXE | 1,2 |確定| Hii |你好|,| AAA |
You can choose more than answers.
int main(int argc, char argv[]){ }
int main(int argc, char* argv[]){ }
int main(int argc, char** argv){ }
int main(int* argc, char* argv[]){ }
int main(int argc, char* argv[]){ } and int main(int argc, char** argv){ }
您可以選擇多個答案。
int main(int argc,char argv []){}
int main(int argc,char * argv []){}
int main(int argc,char ** argv){}
int main(int * argc,char * argv []){}
int main(int argc,char * argv []){}和int main(int argc,char ** argv){}
C:\TC\BIN>prg_2 Include Help .Com
#include <stdio.h>
int main(int argc,char** arg)
{
printf("%s",arg[argc]);
return 0;
}
(null)
.Com
Help
C:\TC\BIN>prg_2.exe
(null)
argc contains the total number of arguments passed through command prompt, in this program value of argc will be 3, and the given arguments will store into arg[] from 0 to 2 index.
So arg[argc] => arg[3] will return null.
C:\ TC \ BIN> prg_2包括幫助.Com
(空值)
.Com
救命
C:\ TC \ BIN> prg_2.exe
(空值)
argc包含通過命令提示符傳遞的參數總數,在此程序中argc的值為3,并且給定參數將從0到2索引存儲到arg []中 。
因此arg [argc] => arg [3]將返回null。
C:\TC\BIN>prg_3 10 20 30
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[])
{
int answer;
answer=atoi(argv[1])+atoi(argv[2]);
printf("%d",answer);
return 0;
}
50
60
0
30
30
1st, 2nd argument of argv are 10 and 20.
C:\ TC \ BIN> prg_3 10 20 30
50
60
0
30
30
argv的1st , 2nd參數是10和20。
翻譯自: https://www.includehelp.com/c-programs/c-command-line-argument-aptitude-questions-and-answers.aspx
aptitude 命令