C++ Primitive Data Types

1. Numeric Data Types( 9 kinds )

    Name Synonymy Strorage Size

    short   short int  16-bit signed

    unsigned short  unsigned short int  16-bit unsigned

    int --- 32-bit signed

    unsigned int  unsigned 32-bit unsigned

    long long int  32-bit signed

    unsigned long  unsigned long int  32-bit unsigned

    float --- 32-bit IEEE 754

    double --- 64-bit IEEE 754

    long double  --- 80-bit

 

2. Numeric Type Convertions

  • if one of the operands is long double, the other is converted into long double;
  • Otherwise, if one of the operands is double, the other is converted into double;
  • Otherwise, if one of the operands is float, the other is converted into float;
  • Otherwise, if one of the operands is unsigned long, the other is converted into unsigned long;
  • Otherwise, if one of the operands is long, the other is converted into long;
  • Otherwise, if one of the operands is unsigned int, the other is converted into unsigned int;
  • Otherwise, both operands are converted into int.
      Casting Operator : static_cast<type>(value)

3.  Character Data Type
     Name StorageSize
     char                         1 character 

4. Casting between char and Numeric Types
  • char can be cast into any numberic type, and vice versa.
  • When an integer is cast into a char, only its lower 8 bits of data are used.
  • When a floating-point value is cast into a char, the floating-point vlaue is first cast into an int, which is then cast into a char.
5. bool Data Type
    Name StorageSize
    bool                        1 character 
    In C++, any nonzero value evaluates true and zero value evaluates false.
 

6. widening a type v.s. narrowing a type 

  • widening a type : casting a variable of a type with a small range to a variable of a type with a larger range.
  • narrowing a type : casting a variable of a type with a large range to a variable of a type with a smaller range. 
  • Narrowing a type may lose precision.
7. switch ( switch-expression )
    In C++, a char or bool value is treated as an integral. So, this type of value used in a switch statement as a switch expression or case value.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值