示例
#include <stdio.h>
#include <stdint.h>
//引入bool类型,C99标准新增
#include <stdbool.h>
#include <windows.h>
//对于不支持C99的编译器可以通过宏定义bool类型
//#define bool int
//#define true 1
//#define false 0
int main(void)
{
bool b = true;
bool b0 = false;
//赋任何非0值,b1都等于1
bool b1 = 0;
bool b2 = -5;
bool b3 = 5;
printf("b=%d, b0=%d b1=%d b2=%d b3=%d\n", b, b0, b1, b2, b3);
printf("bool size=%u", sizeof(bool));
getchar();
return 0;
}
运行测试