C MCQs on “Error Handling”.
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
Answer: d
Clarification: 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
Answer: d
Clarification: 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
Answer: d
Clarification: 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
Answer: a
Clarification: EDOM is reported on a domain error.
5. ERANGE is reported on an overflow or an underflow.
a) true
b) false
Answer: a
Clarification: 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 valuen"); else printf("Valid valuen");
a) Invalid value
b) Valid value
c) No output
d) Compile error
Answer: b
Clarification: 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 valuen");
a) Invalid value
b) Valid value
c) No output
d) Compile error
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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.