本博客已迁往http://coredumper.cn
ANSI C中是没有bool类型的,C99中引入了bool类型,具有true(也就是1)和false(也就是0)两种值,但是需要包含头文件stdbool.h之后才可以使用。
我们完全可以用枚举类型来模拟bool类型,如下所示:
typedef enum{
false, true
}bool;
bool test(int a)
{
if(a > 0){
return true;
}
else{
return false;
}
}
int main(void)
{
bool result;
result = test(1);
return 0;
}
本文介绍了C99标准中引入的bool类型及其使用方法。通过包含stdbool.h头文件,可以使用true和false两个值。此外,还提供了一个用枚举类型模拟bool类型的示例。

1006

被折叠的 条评论
为什么被折叠?



