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.
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?
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).
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
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.
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
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);
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).
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
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?
d) no function called
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.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice BCA MCQs
- Buy Computer Science Books
- Buy C Books
- Apply for C Internship
- Apply for Computer Science Internship