C Questions and Answers – Diagnostics – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Diagnostics – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. The header file assert.h of the C Standard Library defines ________ macro.
a) stderr
b) stdarg
c) setjmp
d) assert
View Answer

Answer: d
Explanation: The header file assert.h of the C Standard Library defines a macro called assert is used to verify assumptions made by the program and print a diagnostic message if this assumption is false.

2. What is the name of the macro that is referred by assert macro defined in assert .h?
a) STDARG
b) SETJMP
c) NDEBUG
d) STDERR
View Answer

Answer: c
Explanation: The header file <assert. h> defines the assert macro and refers to another macro, NDEBUG which is not defined by <assert.h>.
advertisement
advertisement

3. If NDEBUG is defined as a macro name, at the point where <assert.h> is included, then assert macro is defined as #define assert(ignore) ((void)0).
a) true
b) false
View Answer

Answer: a
Explanation: If NDEBUG is defined as a macro name at the point in the source file where is included, then the assert macro is defined as #define assert(ignore) ((void)0) .

4. The assert shall be implemented as a ______ not as an actual ________
a) function, macro
b) macro, function
c) header, macro
d) macro, header
View Answer

Answer: b
Explanation: assert shall be implemented as a macro and not a function, which is used to add diagnostics information in your C program. The behavior is undefined if the macro definition is suppressed to access an actual function.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

5. The assert macro returns__________value.
a) integer
b) float
c) double
d) no
View Answer

Answer: d
Explanation: No value is returned by the macro assert.

6. The macro void assert(int expression) allows the diagnostic information to be written in which of the following files?
a) standard error file
b) output file
c) string file
d) character file
View Answer

Answer: a
Explanation: The macro assert prints diagnostic information on the standard error file(stderr). The assert macro writes the information about the particular call that failed (including the text of the argument, name of the source file and the source line number) on the standard error file in an implementation-defined format.
advertisement

7. Which is the correct declaration of macro assert?
a) void assert(int expression);
b) void assert(float expression);
c) void assert(double expression);
d) void assert( expression);
View Answer

Answer: a
Explanation: The right declaration of the macro assert defined under the header file assert.h is void assert(int expression), expression can be any variable.

8. If the expression in void assert(int expression) is zero then a message is printed on stderr(standard error file).
a) true
b) false
View Answer

Answer: a
Explanation: When the expression in the macro void assert(int expression) is zero then the macro displays error message on stderr.
advertisement

9. void assert(int expression) when the expression is evaluated to true?
a) assert returns integer value
b) assert displays error message
c) assert returns nothing
d) assert displays pattern
View Answer

Answer: c
Explanation: void assert(int expression), expression can be a variable or any C expression. If the expression evaluates to TRUE, assert() does nothing.

10. Which function is called by macro assert to terminate the execution?
a) exit()
b) atexit()
c) abort()
d) no function called
View Answer

Answer: c
Explanation: assert macro calls abort() to abnormally terminate the execution. When the expression of the macro is zero then an error message is displayed on the standard error file and then the program execution is aborted.

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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
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 & discussions at Telegram SanfoundryClasses.