qianqiang129
断言的应用

1
#include <stdio.h> 2 //disable the assert function if "NDEBUG" defined 3 //#define NDEBUG 4 #include <assert.h> 5 6 void print_number(int* myInt) { 7 assert (myInt!=NULL); 8 printf ("%d\n",*myInt); 9 } 10 11 int main (int argc, char* argv[]) 12 { 13 int a=10; 14 int * b = NULL; 15 int * c = NULL; 16 17 b=&a; 18 //comment this line to generate an assert 19 //c=&argc; 20 21 print_number (b); 22 print_number (c); 23 24 return 0; 25 }

输出结果举例:

  10
  Assertion failed: myInt!=NULL, file C:\_Tasks\_VC6.0\Temp\Hello.cpp, line 7
  Press any key to continue

 

分类:

技术点:

相关文章:

  • 2021-11-06
  • 2021-11-06
  • 2021-07-07
  • 2021-11-06
  • 2021-05-25
猜你喜欢
  • 2021-11-06
  • 2021-11-16
  • 2021-12-23
  • 2021-12-23
  • 2021-11-06
  • 2021-11-06
  • 2022-01-08
相关资源
相似解决方案