c和c++中使用assert()函数来实现断言。

eg:

#include <stdio.h>
#include <assert.h>

int main()
{
int x = 7;
x = 9;

assert(x==7);

/* Rest of the code */

return 0;
}


执行结果如下:
断言与忽略断言

 

当执行如下命令时,会去掉assert功能,

#define NDEBUG // 忽略断言
 
 
 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2021-12-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2021-04-01
  • 2021-09-18
相关资源
相似解决方案