C MCQ set number 00683

1. A program that has no command line arguments will have argc
a) Zero
b) Negative
c) One
d) Two

Answer

Answer: c [Reason:] None.

2. The index of the last argument in command line arguments is
a) argc – 2
b) argc + 1
c) argc
d) argc – 1

Answer

Answer: d [Reason:] None.

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

  1.     #include <stdio.h>
  2.     int main(int argc, char *argv[])
  3.     {
  4.         printf("%dn", argc);
  5.         return 0;
  6.     }

a) 0
b) 1
c) Depends on the platform
d) Depends on the compiler

Answer

Answer: b [Reason:] None.

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

  1.     #include <stdio.h>
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (argc--)
  5.         printf("%sn", argv[argc]);
  6.         return 0;
  7.     }

a) Compile time error
b) Executablefilename
c) Segmentation fault
d) Undefined

Answer

Answer: b [Reason:] None.

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

  1.     #include <stdio.h>
  2.     int main(int argc, char *argv[])
  3.     {
  4.         printf("%sn", 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

Answer: a [Reason:] None.

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

  1.     #include <stdio.h>
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (*argv++ != NULL)
  5.         printf("%sn", *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

Answer: a [Reason:] None.

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

  1.     #include <stdio.h>
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (*argv  !=  NULL)
  5.         printf("%sn", *(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

Answer: b [Reason:] None.

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

  1.     #include <stdio.h>
  2.     int main(int argc, char *argv[])
  3.     {
  4.         while (argv != NULL)
  5.         printf("%sn",  *(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

Answer: a [Reason:] None.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.