Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Command Line Arguments

C Programming Questions and Answers – Command Line Arguments

 

1.What does argv and argc 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

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) Both (a) and (b)

View Answer

 

Answer:a

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

 

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

 

5.What would be the output if we try to execute following segment of code (assuming the following input “cool brother in city”)?

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

a) (null)

b) City

c) In

Segmentation Fault

View Answer

Answer:a

 

6.The first argument in command line arguments is

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) Both a & b

View Answer

Answer:a

 

7.The second (argument vector) in command line arguments is

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) Both a & b

View Answer

Answer:b

 

8.argv[0] in command line arguments, is

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) Both a & b

View Answer

Answer:a

 

 

9.A program that has no command line arguments will have argc

a) Zero

b) Negative

c) One

d) Two

View Answer

Answer:c

 

10.The index of the last argument in command line arguments is

a) argc – 2

b) argc + 1

c) argc

d) argc – 1

View Answer

Answer:d

 

11.What is the output of this C code (if run with no options or arguments)?

 

#include <stdio.h>

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

{

printf(“%d\n”, argc);

return 0;

}

a) 0

b) 1

c) Depends on the platform

d) Depends on the compiler

View Answer

Answer:b

 

12.What is the output of this C code (run without any commandline arguments)?

 

#include <stdio.h>

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

{

while (argc–)

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

return 0;

}

a) Compile time error

b) Executablefilename

c) Segmentation fault

d) Undefined

View Answer

Answer:b

 

13.What is the output of this C code (run without any commandline arguments)?

 

#include <stdio.h>

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

{

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

return 0;

}

a) Segmentation fault/code crash

b) Executable file name

c) Depends on the platform

d) Depends on the compiler

View Answer

Answer:a

 

14.What is the output of this C code (run without any commandline arguments)?

 

#include <stdio.h>

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

{

while (*argv++ != NULL)

printf(“%s\n”, *argv);

return 0;

}

a) Segmentation fault/code crash

b) Executable file name

c) Depends on the platform

d) Depends on the compiler

View Answer

Answer:a

 

15.What is the output of this C code (run without any command line arguments)?

 

#include <stdio.h>

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

{

while (*argv  !=  NULL)

printf(“%s\n”, *(argv++));

return 0;

}

a) Segmentation fault/code crash

b) Executable file name

c) Depends on the platform

d) Depends on the compiler

View Answer

Answer:b

 

16.What is the output of this C code(run without any command line arguments)?

 

#include <stdio.h>

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

{

while (argv != NULL)

printf(“%s\n”,  *(argv++));

return 0;

}

a) Segmentation fault/code crash

b) Executable file name

c) Depends on the platform

d) Depends on the compiler

View Answer

 

Answer:a

Related Articles

Leave a Reply

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

Back to top button