C Questions and Answers – Diagnostics – 1

«
»

This set of C MCQs focuses on “Diagnostics – 1”.

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

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

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

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.

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

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.

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

Sanfoundry Global Education & Learning Series – C Programming Language.

advertisement
advertisement
advertisement

Leave a Comment

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