zoukankan      html  css  js  c++  java
  • bool类型

    bool类型

    //与C语言相比,C++添加了一种基本类型 —— bool类型,用来表示true和false
    //true和false是字面值,可以通过转变为int类型,true是1,false是0
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
      int x = true;
      int y = false;
      
      cout << "true = " << true << endl;
      cout << "x = " << x << endl;
      cout << "false = " << false << endl;
      cout << "y = " << y << endl;
      return 0;
    }
    
    //任何数字或指针值都可以隐式转换为bool值
    //任何非零值都将转换为true,而零值转换为false
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
      bool x = -100;
      bool y = 0;
      bool z = 100;
      bool yes = true;
      bool no = false;
    
      cout << "x = " << x << endl;
      cout << "y = " << y << endl;
      cout << "z = " << z << endl;
      cout << "yes = " << yes << endl;
      cout << "no = " << no << endl;
    
      return 0;
    }
    
    //一个bool类型的数据占据的内存空间大小为1
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
      cout << "sizeof(bool) = " << sizeof(bool) << endl;
      cout << "sizeof(true) = " << sizeof(true) << endl;
      cout << "sizeof(false) = " << sizeof(false) << endl;
    
      return 0;
    }
    
  • 相关阅读:
    使用paramiko的问题记录
    python常见异常及解决方法
    linux ps -aux各列含义
    常用技能
    超时程序管理
    跨年的总结和展望
    java json和对象互转
    一些常用功能总结
    ResultSet转成java类对象
    python常用功能总结
  • 原文地址:https://www.cnblogs.com/xkyrl/p/14669029.html
Copyright © 2011-2022 走看看