aptitude 命令_C-命令行参数Aptitude问题与解答

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
#include <stdio.h>
int main(int argc,char* argv[])
{
	printf("%d",argc);
	return 0;
}

  1. 4

  2. 5

  3. 6

  4. 3

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.
1)该程序(prg_1.c)的输出是什么? 如果输入命令是
C:\ TC \ BIN> prg_1 includehelp.com C C ++ Java
  1. 4

  2. 5

  3. 6

  4. 3

回答
正确答案-2
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
#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;
}

  1. C:\TC\BIN\PRG_2.EXE|1,2|Ok|Hii|Hello|,|AAA|

  2. ERROR: Invalid argument list.

  3. C:\TC\BIN\PRG_2.EXE|1|,|2|Ok|Hii|Hello|,|AAA|

  4. 1,2|Ok|Hii|Hello|,|AAA|

Answer
Correct Answer - 1
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
  1. C:\ TC \ BIN \ PRG_2.EXE | 1,2 |确定| Hii |你好|,| AAA |

  2. 错误:无效的参数列表。

  3. C:\ TC \ BIN \ PRG_2.EXE | 1 |,| 2 | OK | Hii | Hello |,| AAA |

  4. 1,2 |确定| Hii |你好|,| AAA |

回答
正确答案-1
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.
  1. int main(int argc, char argv[]){ }

  2. int main(int argc, char* argv[]){ }

  3. int main(int argc, char** argv){ }

  4. int main(int* argc, char* argv[]){ }

Answer
Correct Answer - 2 and 3
int main(int argc, char* argv[]){ } and int main(int argc, char** argv){ }
3)用命令行参数声明main的正确格式是什么?
您可以选择多个答案。
  1. int main(int argc,char argv []){}

  2. int main(int argc,char * argv []){}

  3. int main(int argc,char ** argv){}

  4. int main(int * argc,char * argv []){}

回答
正确答案-2和3
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
#include <stdio.h>
int main(int argc,char** arg)
{
	printf("%s",arg[argc]);
	return 0;
}

  1. (null)

  2. .Com

  3. Help

  4. C:\TC\BIN>prg_2.exe

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.
4)该程序(prg_2.c)的输出是什么? 如果输入命令是
C:\ TC \ BIN> prg_2包括帮助.Com
  1. (空值)

  2. .Com

  3. 救命

  4. C:\ TC \ BIN> prg_2.exe

回答
正确答案-1
(空值)
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
#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;
}


  1. 50

  2. 60

  3. 0

  4. 30

Answer
Correct Answer - 4
30
1 st, 2 nd argument of argv are 10 and 20.
5)该程序(prg_2.c)的输出是什么? 如果输入命令是
C:\ TC \ BIN> prg_3 10 20 30
  1. 50

  2. 60

  3. 0

  4. 30

回答
正确答案-4
30
argv的 1st2nd参数是10和20。

翻译自: https://www.includehelp.com/c-programs/c-command-line-argument-aptitude-questions-and-answers.aspx

aptitude 命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值