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.
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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.