250+ TOP MCQs on Diagnostics and Answers

C MCQs on “Diagnostics – 1”.

1. The header file assert.h of the C Standard Library defines ________ macro.
a) stderr
b) stdarg
c) setjmp
d) assert
Answer: d
Clarification: 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
Answer: c
Clarification: The header file defines the assert macro and refers to another macro, NDEBUG which is not defined by .

3. If NDEBUG is defined as a macro name, at the point where is included, then assert macro is defined as #define assert(ignore) ((void)0).
a) true
b) false
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: d
Clarification: No value is returned by the macro assert.

  250+ TOP MCQs on Goto & Labels and Answers

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
Answer: a
Clarification: 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);
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: c
Clarification: 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

Answer: c
Clarification: 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top