C Questions and Answers – Error Handling

«
»

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.

advertisement

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

Answer: d
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

Answer: d
Explanation: A significance loss occurs when a result has nowhere near the number of significant digits indicated by its type.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

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

Answer: d
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

Answer: a
Explanation: EDOM is reported on a domain error.
advertisement

5. ERANGE is reported on an overflow or an underflow.
a) true
b) false
View Answer

Answer: a
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?

advertisement
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

Answer: b
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.
advertisement

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

Answer: a
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

Answer: a
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

Answer: a
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

Answer: b
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.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.