c++ bool

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void)
{
    bool b = 100;
    bool c = false;
    cout<<b<<endl;//运行结果为1
    cout<<c<<endl;//运行结果为0
    return 0;
}  

二、解释

    1、bool型变量取值为true or false,vc++占用一个字节。

    2、把其他变量转换为bool类型时,非0值转换为true,0值转换为false。所以输出时当成整数用,true为1,false为0

参考:https://blog.csdn.net/jltxgcy/article/category/1337702

猜你喜欢

转载自blog.csdn.net/fu6543210/article/details/81674457
今日推荐