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
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
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
Explanation: If NDEBUG is defined as a macro name at the point in the source file where
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
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.
5. The assert macro returns__________value.
a) integer
b) float
c) double
d) no
View Answer
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
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
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
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
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
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.
- Check C Books
- Watch Advanced C Programming Videos
- Check Computer Science Books
- Apply for C Internship
- Apply for Computer Science Internship