C 编程/stdbool.h
外观
< C 编程
(重定向自 C 编程/C 参考/stdbool.h)头文件stdbool.h位于 C 编程语言的 C 标准库中,包含四个用于布尔数据类型的宏。此头文件在 C99 中引入。
ISO C 标准中定义的宏为
- 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; // Could also be `bool keep_going = 1;`
while(keep_going) {
printf("This will run as long as keep_going is true.\n");
keep_going = false; // Could also be `keep_going = 0;`
}
printf("Stopping!\n");
return EXIT_SUCCESS;
}
将输出
This will run as long as keep_going is true. Stopping!
- : 布尔类型和值 – 基本定义参考,单一 UNIX® 规范,第 7 版,来自开放组