C Programming Questions and Answers on Command Line Arguments for Freshers

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_22.html
1. What does argv and argc indicate in command-line arguments?
(Assuming: int main(int argc, char *argv[]) )
(Assuming: int main(int argc, char *argv[]) )
a) argument count, argument variable
b) argument count, argument vector
c) argument control, argument variable
d) argument control, argument vector
Answer: b
2. Which of the following syntax is correct for command-line arguments?
a) int main(int var, char *varg[]) b) int main(char *argv[], int argc) c) int main() { int argv, char *argc[]; } d) none of the mentioned
Answer: a
3. In linux, argv[0] by command-line argument can be occupied by
a) ./a.out
b) ./test
c) ./fun.out.out
d) all of the mentioned
Answer: d
4. What type of array is generally generated in Command-line argument?
a) Single dimension array
b) 2-Dimensional Square Array
c) Jagged Array
d) 2-Dimensional Rectangular Array
Answer: c
5. What would be the output if we try to execute following segment of code (assuming the following input “cool brother in city”)?
printf(“%s\n”, argv[argc]);
a) (null)
b) City
c) In
D. Segmentation Fault
b) City
c) In
D. Segmentation Fault
Answer: a
6. The first argument in command line arguments is
a) The number of command-line arguments the program was invoked with;
b) A pointer to an array of character strings that contain the arguments
c) Nothing
d) None of the mentioned
Answer: a
7. The second (argument vector) in command line arguments is
a) The number of command-line arguments the program was invoked with;
b) A pointer to an array of character strings that contain the arguments,one per string.
c) Nothing
d) None of the mentioned
Answer: b
8. argv[0] in command line arguments, is
a) The name by which the program was invoked
b) The name of the files which are passed to the program
c) Count of the arguments in argv[] vector
d) None of the mentioned
Answer: a
9. A program that has no command line arguments will have argc
a) Zero
b) Negative
c) One
d) Two
Answer: c
10. The index of the last argument in command line arguments is
a) argc – 2
b) argc + 1
c) argc
d) argc – 1
Answer: d
11. What is the output of this C code (if run with no options or arguments)?
#include
int main(int argc, char *argv[])
{
printf("%d\n", argc);
return 0;
}
a) 0
b) 1
c) Depends on the platform
d) Depends on the compiler
b) 1
c) Depends on the platform
d) Depends on the compiler
Answer: b
12. What is the output of this C code (run without any commandline arguments)?
#include
int main(int argc, char *argv[])
{
while (argc--)
printf("%s\n", argv[argc]);
return 0;
}
a) Compile time error
b) Executablefilename
c) Segmentation fault
d) Undefined
b) Executablefilename
c) Segmentation fault
d) Undefined
Answer: b
13. What is the output of this C code (run without any commandline arguments)?
#include
int main(int argc, char *argv[])
{
printf("%s\n", argv[argc]);
return 0;
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: a
14. What is the output of this C code (run without any commandline arguments)?
#include
int main(int argc, char *argv[])
{
while (*argv++ != NULL)
printf("%s\n", *argv);
return 0;
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: a
15. What is the output of this C code (run without any command line arguments)?
#include
int main(int argc, char *argv[])
{
while (*argv != NULL)
printf("%s\n", *(argv++));
return 0;
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: b
16. What is the output of this C code(run without any command line arguments)?
#include
int main(int argc, char *argv[])
{
while (argv != NULL)
printf("%s\n", *(argv++));
return 0;
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: a