`
Jia_er
  • 浏览: 10981 次
  • 性别: Icon_minigender_2
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

C++ Primitive Data Types

    博客分类:
  • C++
阅读更多

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.

 

分享到:
评论

相关推荐

    google search client api for c/c++

    /*start primitive data types*/ #ifdef _SOAP_TYPES typedef char * xsd__string;;;; typedef int xsd__int;;;; struct xsd__base64Binary { unsigned char *__ptr;;;; int __size;;;; };;;; typedef ...

    Addison.Wesley.C++.by.Dissection.2002.pdf

    - **Simple Types:** Explains primitive data types such as integers, floats, and characters. - **Initialization:** Describes different methods of initializing variables. - **The Traditional Conversions...

    Pattern Recognition with Neural Networks in C++

    Chapter 5—Some Other Types of Neural Networks 5.1 General 5.2 Radial Basis Function Networks 5.2.1 Network Architecture 5.2.2 RBF Training 5.2.3 Applications of RBF Networks 5.3 Higher ...

    Sammie Bae - JavaScript Data Structures and Algorithms - 2019.pdf

    objects and types. Then, this book covers implementations and algorithms for fundamental data structures such as linked lists, stacks, trees, heaps, and graphs. Finally, more advanced topics such as ...

    程序语言设计原理习题解答

    6.2 Primitive Data Types 253 6.3 Character String Types 256 History Note 258 6.4 User-Defined Ordinal Types 261 6.5 Array Types 266 History Note 267 History Note 269 6.6 Associative ...

    2021Java零基础自学笔记资源(六)数据类型(上)

    在Java中,数据类型分为两大类:基本数据类型(Primitive Data Types)和引用数据类型(Reference Data Types)。 基本数据类型是Java语言预定义的,它们包括四种类别: 1. 整数型(Integer Types):byte、short...

    Beginning Rust

    Beginning Rust starts with the basics of Rust, including how to name objects, control execution flow, and handle primitive types. You’ll see how to do arithmetic, allocate memory, use iterators, and ...

    CUDA11.0-C-Programming-Guide.pdf

    - The guide includes information on using tf32 and Bfloat16 data types, along with double precision tensor cores, through the Warp Matrix Functions API. This enables more efficient computation for ...

    D3D render pipeline

    Chapter 16 describes the abstract data types provided by D3DX. D3DX provides support for RGBA color, point, vector, plane, quaternion, and matrix data types. Chapter 17 describes the helper ...

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    Chapter 8Primitives as Typesexplores the relationship between the primitive types and objects of their corresponding wrapper classes, and how boxing and unboxing can transparently convert between ...

    C#命名规范

    - 对于基本类型(`primitive types`)的局部变量,使用Camel命名规则,例如: ```csharp int type = 0; double count = 0; ``` - 对于`string`类型,通常使用`str`前缀加上Pascal命名,例如: ```csharp string ...

Global site tag (gtag.js) - Google Analytics