This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Command Line Arguments – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. A program that has no command line arguments will have argc _________
a) Zero
b) Negative
c) One
d) Two
View Answer
Explanation: None.
2. What is the index of the last argument in command line arguments?
a) argc – 2
b) argc + 1
c) argc
d) argc – 1
View Answer
Explanation: None.
3. What will be the output of the following 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
Explanation: None.
4. What will be the output of the following C code (run without any command line 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
Explanation: None.
5. What will be the output of the following C code (run without any command line 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
Explanation: None.
6. What will be the output of the following 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
Explanation: None.
7. What will be the output of the following 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
Explanation: None.
8. What will be the output of the following 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
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Apply for C Internship
- Practice Computer Science MCQs
- Buy Computer Science Books