250+ TOP MCQs on Error Handling and Answers

C MCQs (multiple choice questions) on “Error Handling”. One shall practice these MCQs to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our multiple choice questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C multiple choice questions on “Error Handling” along with answers, explanations and/or solutions:

1. What is the output of the following C code if there is no error in stream fp?

  1.     #include 
  2.     int main()
  3.     {
  4.         FILE *fp;
  5.         fp = fopen("newfile", "w");
  6.         printf("%dn", ferror(fp));
  7.         return 0;
  8.     }

a) Compilation error
b) 0
c) 1
d) Any nonzero value
Answer: b
Clarification: None.

2. Within main, return expr statement is equivalent to ________
a) abort(expr)
b) exit(expr)
c) ferror(expr)
d) none of the mentioned
Answer: b
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         FILE *fp;
  5.         char c;
  6.         int n = 0;
  7.         fp = fopen("newfile1.txt", "r");
  8.         while (!feof(fp))
  9.         {
  10.             c = getc(fp);
  11.             putc(c, stdout);
  12.         }
  13.     }

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
Answer: d
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         FILE *fp = stdout;
  5.         stderr = fp;
  6.         fprintf(stderr, "%s", "hello");
  7.     }

a) Compilation error
b) hello
c) Undefined behaviour
d) Depends on the standard
Answer: b
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char buf[12];
  5.         stderr = stdin;
  6.         fscanf(stderr, "%s", buf);
  7.         printf("%sn", buf);
  8.     }

a) Compilation error
b) Undefined behaviour
c) Whatever user types
d) None of the mentioned
Answer: c
Clarification: None.

6. stderr is similar to?
a) stdin
b) stdout
c) both stdout and stdin
d) none of the mentioned
Answer: a
Clarification: 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
Answer: a
Clarification: 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();
Answer: b
Clarification: None.

  250+ TOP MCQs on Enums and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top