C Command Line Arguments

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