Table of Contents

assert

    void assert(scalar expression);

With assert you can test your programm for logical errors.

The assert () macro will insert diagnostics into programs

When executed, if expression (which is a scalar type you have) is false (ie, compares equal to 0),
assert (), provide information about the particular call that failed to stderr and abort ()

C Sourcecode Example

#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
#include <assert.h>
 
int testfunc(int a, int b) {
   assert( (a >= 0 && a >= b) && (b >= 0) );
   return a / b;
}
 
int main ( void ) {
printf("9 / 4 = %d\n", testfunc(9, 4) );
printf("1 / 1 = %d\n", testfunc(1, 1) );
printf("0 / 9 = %d\n", testfunc(0, 9) );
return 0;
}

Output

  user@host:~$ ./assert 
  9 / 4 = 2
  1 / 1 = 1
  assert: assert.c:6: testfunc: Assertion `(a >= 0 && a >= b) && (b >= 0)' failed.
  canceled