C Command Line Arguments

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

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

1 #include <stdio.h>
2 int main(int argc,char* argv[])
3 {
4 printf("%d",argc);
5 return 0;
6 }

1. 4
2. 5
3. 6
4. 3

Answer

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

1 #include <stdio.h>
2 int main(int counter,char** arg)
3 {
4 unsigned char tally;
5 for(tally=0;tally< counter; tally+=1)
6 printf("%s|",arg[tally]);
7 return 0;
8 }

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

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

4) What will be the output of this program (prg_2.c)? If input command is


C:\TC\BIN>prg_2 Include Help .Com

1 #include <stdio.h>
2 int main(int argc,char** arg)
3 {
4 printf("%s",arg[argc]);
5 return 0;
6 }

1. (null)
2. .Com
3. Help
4. C:\TC\BIN>prg_2.exe

Answer

5) What will be the output of this program (prg_2.c)? If input command is


C:\TC\BIN>prg_3 10 20 30

1 #include <stdio.h>
2 #include <stdlib.h>
3 int main(int argc,char* argv[])
4 {
5 int answer;
6
7 answer=atoi(argv[1])+atoi(argv[2]);
8 printf("%d",answer);
9 return 0;
10 }

1. 50
2. 60
3. 0
4. 30

Answer

You might also like