Here is a listing of C Objective Questions on “Command Line Arguments” along with answers, explanations and/or solutions:
1. A program that has no command line arguments will have argc _________
a) Zero
b) Negative
c) One
d) Two
Answer: c
Clarification: None.
2. What is the index of the last argument in command line arguments?
a) argc – 2
b) argc + 1
c) argc
d) argc – 1
Answer: d
Clarification: None.
3. What will be the output of the following C code (if run with no options or arguments)?
-
#include
-
int main(int argc, char *argv[])
-
{
-
printf("%dn", argc);
-
return 0;
-
}
a) 0
b) 1
c) Depends on the platform
d) Depends on the compiler
Answer: b
Clarification: None.
4. What will be the output of the following C code (run without any command line arguments)?
-
#include
-
int main(int argc, char *argv[])
-
{
-
while (argc--)
-
printf("%sn", argv[argc]);
-
return 0;
-
}
a) Compile time error
b) Executablefilename
c) Segmentation fault
d) Undefined
Answer: b
Clarification: None.
5. What will be the output of the following C code (run without any command line arguments)?
-
#include
-
int main(int argc, char *argv[])
-
{
-
printf("%sn", argv[argc]);
-
return 0;
-
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: a
Clarification: None.
6. What will be the output of the following C code (run without any command line arguments)?
-
#include
-
int main(int argc, char *argv[])
-
{
-
while (*argv++ != NULL)
-
printf("%sn", *argv);
-
return 0;
-
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: a
Clarification: None.
7. What will be the output of the following C code (run without any command line arguments)?
-
#include
-
int main(int argc, char *argv[])
-
{
-
while (*argv != NULL)
-
printf("%sn", *(argv++));
-
return 0;
-
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: b
Clarification: None.
8. What will be the output of the following C code (run without any command line arguments)?
-
#include
-
int main(int argc, char *argv[])
-
{
-
while (argv != NULL)
-
printf("%sn", *(argv++));
-
return 0;
-
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: a
Clarification: None.