`
Jia_er
  • 浏览: 10423 次
  • 性别: 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.

 

分享到:
评论

相关推荐

    JavaScript Data Structures and Algorithms

    the basic JavaScript foundations, such as primitive objects and types. Then, this book covers implementations and algorithms for fundamental data structures such as linked lists, stacks, trees, heaps,...

    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 ...

    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 ...

    JAVA白皮书(英文版)

    2.1.1Primitive Data Types 2.1.2Arithmetic and Relational Operators 2.1.3Arrays 2.1.4Strings 2.1.5Multi-Level Break 2.1.6Memory Management and Garbage Collection 2.1.7The Background ...

    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 ...

    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 ...

    Thinking in Java 4th Edition

    Special case: primitive types ....... 43 Arrays in Java .............................. 44 You never need to destroy an object .................. 45 Scoping ........................................ 45 ...

Global site tag (gtag.js) - Google Analytics