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)?
-
#include <stdio.h>
-
int main(int argc, char *argv[])
-
{
-
printf("%dn", argc);
-
return 0;
-
}
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)?
-
#include <stdio.h>
-
int main(int argc, char *argv[])
-
{
-
while (argc--)
-
printf("%sn", argv[argc]);
-
return 0;
-
}
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)?
-
#include <stdio.h>
-
int main(int argc, char *argv[])
-
{
-
printf("%sn", argv[argc]);
-
return 0;
-
}
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)?
-
#include <stdio.h>
-
int main(int argc, char *argv[])
-
{
-
while (*argv++ != NULL)
-
printf("%sn", *argv);
-
return 0;
-
}
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)?
-
#include <stdio.h>
-
int main(int argc, char *argv[])
-
{
-
while (*argv != NULL)
-
printf("%sn", *(argv++));
-
return 0;
-
}
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)?
-
#include <stdio.h>
-
int main(int argc, char *argv[])
-
{
-
while (argv != NULL)
-
printf("%sn", *(argv++));
-
return 0;
-
}
a) Segmentation fault/code crash
b) Executable file name
c) Depends on the platform
d) Depends on the compiler
Answer
Answer: a [Reason:] None.