Assert

来源:互联网 发布:淘宝申请部分退款 编辑:程序博客网 时间:2024/06/06 06:42
/* assert example */#include <stdio.h>#include <assert.h>void print_number(int* myInt) {  assert (myInt!=NULL);  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;}
In this example, assert is used to abort the program execution if print_number is called with a null pointer as attribute. This happens on the second call to the function, which triggers an assertion failure to signal the bug.