Table of Contents
This guide covers assert. h in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
Assert. H in C
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
FAQ
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Reader Comments 0
Sign in with email or Google to join the discussion.