代码点读机 / C / true

true C · 常用常量

stdbool.h 定义的布尔真宏,值为 1。

怎么用

bool b = true;

小例子

#include <stdio.h>
#include <stdbool.h>
int main(void) {
    bool b = true;
    if (b) printf("真");
    return 0;
}

运行结果

输出 真

提醒:需要包含 <stdbool.h>;底层仍是整数 1

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

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