• c++ array and pointer


    pointer to const object and const pointer,

    1.指向常量对象的指针,意思是指针所指向的 对象内容不能变(不能够通过指针赋值)。

    2.常量指针,意思是指针内容不能变,指向对象a就不能改为指向对象b(指针不能指向别处)。
    (简单来说就是const挨着哪个近,哪个就不能变。)

    pointer to const object:
    const double *cptr; // cptr may point to a double that is const
    
    
    const double pi = 3.14;
    double *ptr = π // error: ptr is a plain pointer
    const double *cptr = π // ok: cptr is a pointer to const
    
    const int universe = 42;
    const void *cpv = &universe; // ok: cpv is const
    void *pv = &universe; // error: universe is const
    
    const pointer:
    int errNumb = 0;
    int *const curErr = &errNumb; // curErr is a constant pointer
    curErr = curErr; // error: curErr is const
    

    还有个更恶心的,const pointer to a const object

    指向常量对象的常量指针,尼玛两个(pointer and object)都不能变,都是const.

    const double pi = 3.14159;
    // pi_ptr is const and points to a const object
    const double *const pi_ptr = π
    

      

  • 相关阅读:
    USACO 2016 February Contest, Gold解题报告
    USACO 2016 January Contest, Gold解题报告
    NOIP2013 Day2
    [DP题]放苹果
    [DP题]登山
    洛谷八连测R6
    [20171025模拟赛]
    [DP题]吃糖果
    [DP题]采药
    spring-security-oauth2 授权服务集成钉钉扫码登录
  • 原文地址:https://www.cnblogs.com/alazalazalaz/p/5022338.html
Copyright © 2020-2023  润新知