This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Error Handling”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. _______ occurs when a result is too large in magnitude to represent errors as a floating-point value of the required type.
a) underflow
b) significance loss
c) domain
d) overflow
View Answer
Explanation: An overflow occurs when a result is too large in magnitude to represent errors as a floating-point value of the required type.
2. What occurs when a result has nowhere near the number of significant digits indicated by its type.
a) domain
b) underflow
c) overflow
d) significance loss
View Answer
Explanation: A significance loss occurs when a result has nowhere near the number of significant digits indicated by its type.
3. What error occurs when a result is undefined for a given argument value?
a) significance loss
b) underflow
c) overflow
d) domain
View Answer
Explanation: A domain error occurs when a result is undefined for a given argument value.
4.______ is reported on a domain error.
a) EDOM
b) ERANGE
c) Significance loss
d) Underflow
View Answer
Explanation: EDOM is reported on a domain error.
5. ERANGE is reported on an overflow or an underflow.
a) true
b) false
View Answer
Explanation: This macro represents a range error, which occurs if an input argument is outside the range, over which the mathematical function is defined and errno is set to ERANGE.
6. What will be the output of the following C code?
errno = 0; y = sqrt(2); if(errno == EDOM) printf("Invalid value\n"); else printf("Valid value\n");
a) Invalid value
b) Valid value
c) No output
d) Compile error
View Answer
Explanation: The C library macro EDOM represents a domain error, which occurs if an input argument is outside the domain, over which the mathematical function is defined and errno is set to EDOM.
7. What will be the output of the following C code?
errno = 0; y = sqrt(-10); if(errno == EDOM) printf("Invalid value \n"); else printf("Valid value\n");
a) Invalid value
b) Valid value
c) No output
d) Compile error
View Answer
Explanation: The C library macro EDOM represents a domain error, which occurs if an input argument is outside the domain, over which the mathematical function is defined and errno is set to EDOM.
8. errno causes trouble in two subtler ways(vague and explicit).
a) true
b) false
View Answer
Explanation: errno causes trouble in two subtler ways – sometimes its specification is too vague and sometimes it is too explicit.
9. No library function will store a zero in errno.
a) true
b) false
View Answer
Explanation: Any library function can store nonzero values in errno.
10. __________ tells the compiler that this data is defined somewhere and will be connected with the linker.
a) errno
b) extern
c) variable
d) yvals
View Answer
Explanation: The C library macro extern int errno is set by system calls and some library functions in the event of an error to indicate if anything went wrong.
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.
- Apply for Computer Science Internship
- Check C Books
- Practice BCA MCQs
- Check Computer Science Books
- Watch Advanced C Programming Videos