C Programming Questions and Answers – Command Line Arguments – 1

«
»
This section on C interview questions and answers focuses on “Command Line Arguments”. One shall practice these interview questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Command Line Arguments” along with answers, explanations and/or solutions:

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.
advertisement

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

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

b)

advertisement
advertisement
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.
advertisement

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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter