C Programming Questions and Answers on Command Line Arguments for Freshers

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
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) none of the mentioned

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
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
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
D. Segmentation Fault
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) None of the mentioned
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) None of the mentioned
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) None of the mentioned
Answer: a
9. A program that has no command line arguments will have argc

a) Zero
b) Negative
c) One
d) Two
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
Answer: d
11. What is the output of this C code (if run with no options or arguments)?
  1.     #include 
  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
Answer: b
12. What is the output of this C code (run without any commandline arguments)?
  1.     #include 
  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
Answer: b
13. What is the output of this C code (run without any commandline arguments)?
  1.     #include 
  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
Answer: a
14. What is the output of this C code (run without any commandline arguments)?

  1.     #include 
  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
Answer: a
15. What is the output of this C code (run without any command line arguments)?

  1.     #include 
  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
Answer: b
16. What is the output of this C code(run without any command line arguments)?
  1.     #include 
  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
Answer: a

Related

Multiple Choice Questions and Answers on Cloud Types for Freshers

1. _________ model consists of the particular types of services that you can access on a cloud computing platform. a) Serviceb) Deploymentc) Applicationd) None of the mentioned Answer: a Explanat...

Multiple Choice Questions and Answers on Challenges and Obstacles to Cloud Computing for Freshers

1. Which of the following subject area deals with pay-as-you-go usage model? a) Accounting Managementb) Compliancec) Data Privacyd) All of the mentioned Answer: a Explanation: For cloud computing...

Multiple Choice Questions and Answers on Laws of Cloudonomics for freshers

1. _______ blurs the differences between a small deployment and a large one because scale becomes tied only to demand. a) Leadingb) Poolingc) Virtualizationd) All of the mentioned Answer: b Expla...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item