Home » Aptitude Questions and Answers » C Aptitude Questions and Answers

C - Command line arguments Aptitude Questions and Answers



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.

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

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|



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[]){ }

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



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






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.