250+ TOP MCQs on Command Line Arguments and Answers

’s MCQs on C helps anyone preparing for placement in Huawei and other companies. Anyone looking for Huawei placement papers should practice these questions continuously for 2-3 months, thereby ensuring a top position in placements.

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)?

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

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)?

  1.     #include 
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (argc--)
  5.         printf("%sn", argv[argc]);
  6.         return 0;
  7.     }

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)?

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

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)?

  1.     #include 
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (*argv++ != NULL)
  5.         printf("%sn", *argv);
  6.         return 0;
  7.     }

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)?

  1.     #include 
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (*argv  !=  NULL)
  5.         printf("%sn", *(argv++));
  6.         return 0;
  7.     }

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)?

  1.     #include 
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (argv != NULL)
  5.         printf("%sn",  *(argv++));
  6.         return 0;
  7.     }

a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer: a
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *