zoukankan      html  css  js  c++  java
  • c++ 的整形字面值和如何确定常量类型

    #include <iostream>
    using namespace std;
    int main()
    {	
       //整形
       //short至少是16bit
       //int至少与short一样,这里是32bit
       //long至少是32bit,至少与int一样长
       //longlong 至少是64,至少与long一样长
    
       //c++ 通过数字后边的字母来识别常量类型
       cout << "c++通过数字后边的字母识别常量类型" << endl;
       //数字后边加L或者l,意思这是个long类型
       long lValue = 10l;
       cout << "long lValue 10L :" << lValue <<endl;
       //数字后边加U或者u,标志这是个无符号int
       unsigned int uValue = 10u;
       cout << "unsigned 10u is :" << uValue << endl;
       //数字后边带ul表示这是个unsigned long,还有unsigned long long的ull,大小写不敏感
       unsigned long ulValue = 10ul;
       cout << "ulValue 10ul is :" << ulValue << endl;
       //数字后边什么也不带,默认识别成int类型
       int intValue = 10;
       cout << "intValue 10 is :" << intValue << endl << endl; 
    
    
    
       cout << "c++ 通过数字前面的前缀识别进制形式" << endl;
       //数字后边什么也不加,表示是十进制表示的数字。
       int emptyValue = 20;
       cout << endl << "emptyValue 10 is :" << emptyValue << endl;
       //数字前边加0,表示该数值是用8进制表示的
       int zeroValue = 010;
       cout << endl << "010 is :" << zeroValue<<endl;
       cout << oct << "oct 010 is :" << zeroValue<<endl;
       //数字前边加0x,表示该数值是用16进制表示的
       int  hexValue = 0x10;
       cout << endl << "0x10 is :" <<  hexValue << endl;
       cout << hex << "hex 0x10 is :" <<  hexValue << endl;
    
    
       cout << "c++ primer plus page 45." << endl;
    
       return 0;
    }
    
    
    $ ./4.out             
    c++通过数字后边的字母识别常量类型
    long lValue 10L :10
    unsigned 10u is :10
    ulValue 10ul is :10
    intValue 10 is :10
    
    c++ 通过数字前面的前缀识别进制形式
    
    emptyValue 10 is :20
    
    010 is :8
    oct 010 is :10
    
    0x10 is :20
    hex 0x10 is :10
    
  • 相关阅读:
    ajax post 时 form数据serialize()
    dapper 自定义数据库字段和代码中Model字段不一致时候的mapping方法
    TImage 的一些操作
    AOP
    SSL、数字签名、CA 工作原理
    RESTFUL
    tomcat
    Hibernate
    设计模式
    Spring配置
  • 原文地址:https://www.cnblogs.com/feipeng8848/p/12989938.html
Copyright © 2011-2022 走看看