assert - C assert.h

C examples for assert.h:assert

Type

macro

From

<cassert> 
<assert.h> 

Description

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.

Prototype

void assert (int expression); 
       
      

Parameters

Parameter Description
expression Expression to be evaluated. If this expression evaluates to 0, this causes an assertion failure that terminates the program.

Return Value

none

Example

Demo Code


#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;
} 

Related Tutorials