assert.h in C
assert.h in C
The file header named assert.h from Library C provides a macro called assert that can be used to test an assumption made by the program and print a diagnostic message to find the error if this assumption is false .
The macro is predefined assert this reference to another macro is NDEBUG which is not part of. If NDEBUG is defined as a macro name in the source file, where it is included, assert is defined as follows:
#define assert ( ignore ) (( void ) 0 )
The macros are defined in assert.h
In assert.h only define the following macro:
void assert (int expression): This is really a macro and not a function. This macro is used to add diagnostics to find errors in the C program.
Assert macro () in C
The assert () function in C
Macro void assert (int bieu-thuc) in Standard C Library allows detection diagnostic information to be written to standard error file (Standard Error File). In other words, it can be used to add diagnostic messages to find errors in C programming.
Declare assert () function in C
Below is the declaration for the assert () Macro in the standard C Library.
void assert ( int bieu - thuc );
Parameters
bieu-thuc: This can be a variable or any C expression. If the command evaluates to TRUE, then assert () does nothing. If the method evaluates to false, then assert () displays an error message on stderr and stops executing the program.
Return value
This macro does not return any values.
For example
The following C program illustrates the use of assert () macros in Library C:
#include #include int main () { int a ; char str [ 50 ]; printf ( "Nhap mot gia tri nguyen: n" ); scanf ( "%d" , & a ); assert ( a >= 10 ); printf ( "Gia tri nguyen vua nhap la %dn" , a ); printf ( "Nhap mot chuoi: " ); scanf ( "%s" , & str ); assert ( str != NULL ); printf ( "Chuoi vua nhap la: %sn" , str ); return ( 0 ); }
Compile and run the above program to see the results:
According to Tutorialspoint
Previous post: Command line parameter in C
Next story: ctype.h in C
You should read it
- Firefox 14 prohibits Flash by default
- What is a macro in Excel? How to create and run a Macro in Excel
- stdarg.h in C
- The easiest way to Use Macros in Excel
- string.h in C
- How to fix Office error 'The function you are attempting to run contains macros'
- MS Excel 2003 - Lesson 8: Excel Macro - Automate complex tasks
- stddef.h in C
May be interested
- ctype.h in Cthe header file with the name ctype.h of the c library declares some pretty useful functions for checking and mapping characters.
- errno.h in Cthe file header named errno.h in standard c library defines the integer variable errno, which is set by system call and some library functions for errors to indicate that an error is occurring. this macro is an extension of the type of lvalue type int which can be modified, so it can be read and modified by a program.
- float.h in Cthe header file named float.h of library c contains a set of diverse constants (platform dependent) related to floating point real number values.
- limits.h in Cthe file header named limits.h in library c defines the various attributes of different variable types. macros, defined in this header, limit the value of various variable types such as char, int, and long.
- locale.h in Cheader files named locale.h in library c define their own location settings, such as date format and currency symbols.
- math.h in Cheader files named math.h in library c define diverse math functions and a macro. all functions available in this library receive double as a parameter and return the result in type double.