C Programming Questions and Answers – Command Line Arguments – 1

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

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

1. What does argc and argv indicate in command-line arguments?
(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
View Answer

Answer: b
Explanation: None.

2. Which of the following syntax is correct for command-line arguments?
a)

advertisement
advertisement
int main(int var, char *varg[])

b)

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
int main(char *argv[], int argc)

c)

advertisement
    int main()
    {
        int argv, char *argc[];
    }

d) none of the mentioned
View Answer

Answer: a
Explanation: None.
advertisement

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
View Answer

Answer: d
Explanation: All the options mentioned (./a.out, ./test, ./fun.out.out) are simply the command without any argument. A command is always stored as argument vector zero i.e., argv[0] always contain the command where as argv[1], argv[2], etc. contains the arguments to the commands, if any.

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
View Answer

Answer: c
Explanation: None.

5. What will be the output of the following C statement? (assuming the input is “cool brother in city”)

  printf(%s\n”, argv[argc]);

a) (null)
b) City
c) In
d) Segmentation Fault
View Answer

Answer: a
Explanation: None.

6. What is the first argument in command line arguments?
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
View Answer

Answer: a
Explanation: None.

7. What is the second argument in command line arguments?
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
View Answer

Answer: b
Explanation: None.

8. What is argv[0] in command line arguments?
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
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
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 & discussions at Telegram SanfoundryClasses.