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能力问题和解答-通过运行程序传递值,单独的参数值,参数数目等。
1) What will be the output of this program (prg_1.c)? If input command is
C:\TC\BIN>prg_1 includehelp.com C C++ Java
C:\TC\BIN>prg_1 includehelp.com C C++ Java
#include <stdio.h>
int main(int argc,char* argv[])
{
printf("%d",argc);
return 0;
}
Answer
Correct Answer - 2
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.
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.
1)该程序(prg_1.c)的输出是什么?
如果输入命令是
C:\ TC \ BIN> prg_1 includehelp.com C C ++ Java
C:\ TC \ BIN> prg_1 includehelp.com C C ++ Java
回答
正确答案-2
5
main argc的第一个参数包含命令提示符给出的参数总数,包括命令名称,在此命令中,参数总数为5。
5
main argc的第一个参数包含命令提示符给出的参数总数,包括命令名称,在此命令中,参数总数为5。
2) What will be the output of this program (prg_2.c)? If input command is
C:\TC\BIN>prg_2 1,2 "Ok" "Hii" Hello , AAA
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;
}
Answer
Correct Answer - 1
C:\TC\BIN\PRG_2.EXE|1,2|Ok|Hii|Hello|,|AAA|
C:\TC\BIN\PRG_2.EXE|1,2|Ok|Hii|Hello|,|AAA|
2)该程序(prg_2.c)的输出是什么?
如果输入命令是
C:\ TC \ BIN> prg_2 1,2“确定”“ Hii”您好,AAA
C:\ TC \ BIN> prg_2 1,2“确定”“ Hii”您好,AAA
回答
正确答案-1
C:\ TC \ BIN \ PRG_2.EXE | 1,2 |确定| Hii |你好|,| AAA |
C:\ TC \ BIN \ PRG_2.EXE | 1,2 |确定| Hii |你好|,| AAA |
3) Which is the correct form to declare main with command line arguments ?
You can choose more than answers.
You can choose more than answers.
Answer
Correct Answer - 2 and 3
int main(int argc, char* argv[]){ } and int main(int argc, char** argv){ }
int main(int argc, char* argv[]){ } and int main(int argc, char** argv){ }
3)用命令行参数声明main的正确格式是什么?
您可以选择多个答案。
您可以选择多个答案。
回答
正确答案-2和3
int main(int argc,char * argv []){}和 int main(int argc,char ** argv){}
int main(int argc,char * argv []){}和 int main(int argc,char ** argv){}
4) What will be the output of this program (prg_2.c)? If input command is
C:\TC\BIN>prg_2 Include Help .Com
C:\TC\BIN>prg_2 Include Help .Com
#include <stdio.h>
int main(int argc,char** arg)
{
printf("%s",arg[argc]);
return 0;
}
Answer
Correct Answer - 1
(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.
(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.
4)该程序(prg_2.c)的输出是什么?
如果输入命令是
C:\ TC \ BIN> prg_2包括帮助.Com
C:\ TC \ BIN> prg_2包括帮助.Com
回答
正确答案-1
(空值)
argc包含通过命令提示符传递的参数总数,在此程序中 argc的值为3,并且给定参数将从0到2索引存储到 arg []中 。
因此 arg [argc] => arg [3]将返回null。
(空值)
argc包含通过命令提示符传递的参数总数,在此程序中 argc的值为3,并且给定参数将从0到2索引存储到 arg []中 。
因此 arg [argc] => arg [3]将返回null。
5) What will be the output of this program (prg_2.c)? If input command is
C:\TC\BIN>prg_3 10 20 30
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;
}
Answer
Correct Answer - 4
30
1 st, 2 nd argument of argv are 10 and 20.
30
1 st, 2 nd argument of argv are 10 and 20.
5)该程序(prg_2.c)的输出是什么?
如果输入命令是
C:\ TC \ BIN> prg_3 10 20 30
C:\ TC \ BIN> prg_3 10 20 30
回答
正确答案-4
30
argv的 1st , 2nd参数是10和20。
30
argv的 1st , 2nd参数是10和20。
翻译自: https://www.includehelp.com/c-programs/c-command-line-argument-aptitude-questions-and-answers.aspx
aptitude 命令