This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Error Handling – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What is the output of the following C code if there is no error in stream fp?
#include <stdio.h>
int main()
{
FILE *fp;
fp = fopen("newfile", "w");
printf("%d\n", ferror(fp));
return 0;
}
a) Compilation error
b) 0
c) 1
d) Any nonzero value
View Answer
Explanation: None.
2. Within main, return expr statement is equivalent to ________
a) abort(expr)
b) exit(expr)
c) ferror(expr)
d) none of the mentioned
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp;
char c;
int n = 0;
fp = fopen("newfile1.txt", "r");
while (!feof(fp))
{
c = getc(fp);
putc(c, stdout);
}
}
a) Compilation error
b) Prints to the screen content of newfile1.txt completely
c) Prints to the screen some contents of newfile1.txt
d) None of the mentioned
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp = stdout;
stderr = fp;
fprintf(stderr, "%s", "hello");
}
a) Compilation error
b) hello
c) Undefined behaviour
d) Depends on the standard
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char buf[12];
stderr = stdin;
fscanf(stderr, "%s", buf);
printf("%s\n", buf);
}
a) Compilation error
b) Undefined behaviour
c) Whatever user types
d) None of the mentioned
View Answer
Explanation: None.
6. stderr is similar to?
a) stdin
b) stdout
c) both stdout and stdin
d) none of the mentioned
View Answer
Explanation: None.
7. What happens when we use the following C statement?
fprintf(stderr, "error: could not open filen");
a) The diagnostic output is directly displayed in the output
b) The diagnostic output is pipelined to the output file
c) The line which caused error is compiled again
d) The program is immediately aborted
View Answer
Explanation: None.
8. Which of the following function can be used to terminate the main function from another function safely?
a) return(expr);
b) exit(expr);
c) abort();
d) both exit(expr); and abort();
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.
- Check C Books
- Apply for Computer Science Internship
- Practice BCA MCQs
- Check Computer Science Books
- Watch Advanced C Programming Videos