assert C · 常用工具
调试宏,断言条件必须为真,否则程序会报错并终止。
怎么用
assert(条件);
小例子
#include <assert.h>
int main(void) {
int x = 5;
assert(x > 0);
return 0;
}
运行结果
程序正常结束
提醒:发布版定义 NDEBUG 宏可关闭断言;assert 内不要有副作用
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条