C examples for assert.h:assert
macro
<cassert> <assert.h>
If the argument is zero (i.e., the expression is false), a message is written to the standard error device and abort is called, terminating the program execution.
You can add #define NDEBUG as flag to turn on and off the debug mode.
void assert (int expression);
Parameter | Description |
---|---|
expression | Expression to be evaluated. If this expression evaluates to 0, this causes an assertion failure that terminates the program. |
none
#include <stdio.h> #include <assert.h> void print_number(int* myInt) { assert (myInt!=NULL);/* w ww .j a v a 2 s . c o m*/ printf ("%d\n",*myInt); } int main () { int a=10; int * b = NULL; int * c = NULL; b=&a; print_number (b); print_number (c); return 0; }