其他文章:
【C++】C++ true和false代码演示
【JAVA】Java的boolean 和 int互相转换 ——Java的true、false和1、0之间的相互转化
Boolean转化为数字
false为 0,true为 1
数字转化为Boolean
0 为 false; 非 0 为true
以下为C++演示
//Boolean转化为数字
//false为 0,true为 1
bool a = false;
int b = a;
cout << b << endl;
a = true;
b = a;
cout << b<< endl;
//数字转化为Boolean
//0 为 false; 非 0 为true
int c = 0;
bool c1 = c;
if (c1)
{
cout << "true" << endl;
}
else
{
cout << "false" << endl;
}
int d = 99;
bool d1 = d;
if (d1)
{
cout << "true" << endl;
}
else
{
cout << "false" << endl;
}
结果: