stdbool.h - 维基百科,自由的百科全书
C标准函数库 |
---|
一般 |
杂项 |
stdbool.h
是C语言之标准函数库中的一個头文件,在C99中引入,包含四个用于布尔型的预定义宏。
宏定义
[编辑]IEEE 1003.1-2001标准中的宏定义包括:
bool
,会扩展为_Bool
true
,会扩展为1
false
,会扩展为0
__bool_true_false_are_defined
,会扩展为1
示例
[编辑]如下例所示:
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main(void) { bool keep_going = true; //也可以是`bool keep_going = 1;` while(keep_going) { printf("本程序会在keep_going为真时持续运行。\n"); keep_going = false; // 也可以是`keep_going = 0;` } printf("停止运行!\n"); return EXIT_SUCCESS; }
该程序会输出
本程序会在keep_going为真时持续运行. 停止运行!