Error Handling MCQ Questions - C Programming
This section focuses on the "Error Handling" in C programming. These Multiple Choice Questions (MCQ) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Error handling refers to the practice of ____________ that occur during the execution of a program.
A. detecting runtime errors
B. reporting runtime errors
C. handling runtime errors
D. All of the above
View Answer
Ans : D
Explanation: Error handling refers to the practice of detecting, reporting, and handling runtime errors that occur during the execution of a program.
2. When a function is called in C, a variable named as ___________ is automatically assigned a code (value) which can be used to identify the type of error that has been encountered.
A. perror
B. errno
C. strerror
D. exit_failure
View Answer
Ans : B
Explanation: When a function is called in C, a variable named as errno is automatically assigned a code (value) which can be used to identify the type of error that has been encountered.
3. Which of the following returns a pointer to the textual representation of the current errno value?
A. perror
B. errno
C. strerror
D. None of the above
View Answer
Ans : C
Explanation: strerror(): returns a pointer to the textual representation of the current errno value.
4. perror displays the string you pass to it, followed by a colon, a space, and then the textual representation of the current errno value.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, perror displays the string you pass to it, followed by a colon, a space, and then the textual representation of the current errno value.
5. Which of the following is a common technique for error handling in C Programming Language?
A. Using global variables
B. Using try-catch blocks
C. Using exceptions
D. All of the above
View Answer
Ans : A
Explanation: Using global variables is a common technique for error handling in C Programming Language.
6. Within main, return expr statement is equivalent to ________
A. abort(expr)
B. exit(expr)
C. ferror(expr)
D. None of the above
View Answer
Ans : B
Explanation: Within main, return expr statement is equivalent to exit(expr).
7. Which of the following is an example of a runtime error in C Programming?
A. Syntax error
B. Compiler error
C. Divide by zero
D. None of the above
View Answer
Ans : C
Explanation: Divide by zero is an example of a runtime error in C.
8. To detect and handle runtime errors is the purpose of error handling in C.
A. Yes
B. No
C. Can be yes or no
D. Can not say
View Answer
Ans : A
Explanation: Yes, To detect and handle runtime errors is the purpose of error handling in C
9. In C programming language, what does a function return when it encounters an error?
A. A null pointer
B. A warning message
C. An error code
D. All of the above
View Answer
Ans : C
Explanation: An error code return when it encounters an error in C.
10. stderr is similar to?
A. stdin
B. stdout
C. Both stdout and stdin
D. None of the above
View Answer
Ans : B
Explanation: stderr is not exactly the same as stdout, but similar in the sense that both puts the output or error to the monitor.
Discussion