• [StudyNote C++ Primer] Compound Types


    Variables and Basic Types

    Section 2.1 Primitive Built-in Types

    2.1.1 Arithmetic Types

    include two categories: Integral types(character and boolean types) and floating-point types

    char | character | 8bits
    wchar_t | wide character | 16bits
    char16_t | Unicode character | 16bits
    char32_t
    int 16bits
    long 32bits
    float 6 significant digits
    double 10 significant digits

    wchar_t char16_t char32_t etc are used for extended character sets

    the integral types may be signed or unsigned

    A signed type represents negative or positive numbers (including 0)

    and an unsigned type represents only values greater than or equal to 0

    In an unsigned type, all the bits represent the value
    and 8-bit unsigned char can hold the values from 0 through 255 inclusive

    2.1.3 Literals

    the value 20 in three ways:

    20 --- decimal

    024 -- octal (begain with 0)

    0x14 - hexadecimal (begin with 0x or 0X)

    'a' --- character literal

    "Hello World!" --- string literal

    Section 2.3 Compound Types

    A compound type is a type that is defined in terms of another type.

    two of which --- references and pointers

    2.3.1 References

    A reference defines an alternative name for an obj.

    A reference type refers to another type

    int T = 1024;
    int &refT = t; // refT refers to (is another name for) T
    

    we bind the reference to a variable's initializer, rather than its value

    Once initialized, a reference remains bound to its inital object

    int T = 1;
    int &refT = T;
    refT += 1;
    std::cout << T << std::endl; // The value of T is two (for the refT is only another name of T)
    

    2.3.2 Pointers

    A pointer is a compound type that points to another types

    Pointers can be assigned and copied;

    a single pointer can point to several different objects over its lifetime

    A pointer holds the address of another object

    we get the address of an object by using the address-of operator (the $ & $ operator)

    int T = 42;
    int *p = &T;
    
    
  • 相关阅读:
    GC 案例收集整理
    Netty ByteBuf泄露定位修改。
    使用Modernizr 检测HTML5和CSS3浏览器支持功能 (转自http://www.adobe.com/cn/devnet/dreamweaver/articles/using-modernizr.html)
    drupal网站邮件发送功能的实现
    Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 and 7
    WordPress网站迁移
    HTTP协议详解 (转)
    HTTP协议
    Apache服务器放置多个站点的配置方法 (转)
    Apache禁止或允许固定IP访问特定目录、文件、URL
  • 原文地址:https://www.cnblogs.com/chloristendika/p/15831721.html
Copyright © 2020-2023  润新知