C Programming Questions and Answers – Command Line Arguments – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Command Line Arguments – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. A program that has no command line arguments will have argc _________
a) Zero
b) Negative
c) One
d) Two
View Answer

Answer: c
Explanation: 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
View Answer

Answer: d
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

3. What will be the output of the following C code (if run with no options or arguments)?

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

a) 0
b) 1
c) Depends on the platform
d) Depends on the compiler
View Answer

Answer: b
Explanation: None.
advertisement

4. What will be the output of the following C code (run without any command line arguments)?

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

a) Compile time error
b) Executablefilename
c) Segmentation fault
d) Undefined
View Answer

Answer: b
Explanation: None.
advertisement

5. What will be the output of the following C code (run without any command line arguments)?

  1.     #include <stdio.h>
  2.     int main(int argc, char *argv[])
  3.     {
  4.         printf("%s\n", 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
View Answer

Answer: a
Explanation: None.

6. What will be the output of the following C code (run without any command line arguments)?

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

a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
View Answer

Answer: a
Explanation: None.

7. What will be the output of the following C code (run without any command line arguments)?

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

a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
View Answer

Answer: b
Explanation: None.

8. What will be the output of the following C code (run without any command line arguments)?

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

a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
View Answer

Answer: a
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.