代码点读机 / C / stdbool.h

stdbool.h C · 头文件

C99 引入的布尔类型头文件,定义 bool、true、false 三个名字。

怎么用

#include <stdbool.h>

小例子

#include <stdio.h>
#include <stdbool.h>
int main(void) {
    bool ok = true;
    printf("%d", ok);
    return 0;
}

运行结果

输出 1

提醒:它让 C 代码写布尔判断时更清晰;底层仍是整数 0 和非 0

官方文档:https://en.cppreference.com/w/c/types/boolean

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条