Professional Documents
Culture Documents
C Command Line Arguments
C Command Line Arguments
C Command Line Arguments
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
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.
/
Answer
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
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