C99 新增了 _Bool 类型,用于表示布尔值,即逻辑值 true 和 false。
_Bool 类型也是一种整数类型。
原则上 _Bool 类型只占用一位存储空间。
C语言将非 0 的数当为 true,0 当为 false。
表示真或假的变量称为布尔变量 (Boolean variable)
_Bool 是 C 语言中布尔变量的类型名.
_Bool 类型的变量只能储存 1 或 0.
如果把其他非零数值赋值给布尔变量, 则该变量会被设置为 1. 这体现了 C 把所有非零值都视为真.
程序示例:
#include<stdio.h>
int main(void)
{
_Bool a = 10;
printf("%d\n", a);
return 0;
}
结果:
1
代码示例:
#include<stdio.h>
int main(void)
{
int beep = 11;
if (beep)
{
printf("1\n");
}
else
{
printf("2\n");
}
return 0;
}
结果:
1
代码示例:
#include<stdio.h>
int main(void)
{
int beep = 0;
if (beep)
{
printf("1\n");
}
else
{
printf("2\n");
}
return 0;
}
结果:
2
C99 also provides for a stdbool.h header file. This header file makes bool an alias for Bool and defines true and false as symbolic constants for the values 1 and 0. Including this header file allows you to write code that is compatible with C++, which defines bool , true , and false as keywords.
The relational operators are themselves organized into two different precedences.
Higher precedence group: < , <= , > , >=
Lower precedence group: == , !=

7656

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



