250+ TOP MCQs on Command Line Arguments and Answers

C Objective Questions on “Command Line Arguments”. One shall practice these Objective 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 Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective 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
Answer: b
Clarification: None.

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

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

b)

int main(char *argv[], int argc)

c)

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

d) none of the mentioned
Answer: a
Clarification: None.

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
Answer: d
Clarification: 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
Answer: c
Clarification: None.

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

  printf(%sn”, argv[argc]);

a) (null)
b) City
c) In
d) Segmentation Fault
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: a
Clarification: None.

Leave a Reply

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