布尔类型
布尔类型
布尔类型是用来存储true或者false的逻辑值的,它们的数字表示法分别是1和0。
示例:
bool a = true;
bool b = false;
bool c = 1;内置法最多就是1字节,在逻辑表达式里可以注释,各种表达式都能用其他整数——编译器不会产生任何错误,在这种情况下,0值表示成false,其他值表示true。
示例:
int i=5;
double d=-2.5;
if(i) Print("i = ",i," and is set to true");
else Print("i = ",i," and is set to false");
if(d) Print("d = ",d," and has the true value");
else Print("d = ",d," and has the false value");
i=0;
if(i) Print("i = ",i," and has the true value");
else Print("i = ",i," and has the false value");
d=0.0;
if(d) Print("d = ",d," and has the true value");
else Print("d = ",d," and has the false value");
//--- 执行结果
// i= 5 且有真值
// d= -2.5 且有真值
// i= 0 且有错误值
// d= 0 且有错误值