zoukankan      html  css  js  c++  java
  • C++---const

        const int q=50;
        //q=500;  错,q具有const属性不能修改
        //int* p=&q;  错  q相当于常量,不能对常量用&取地址
    //const 修饰指针指向的内容,则内容为不可变量
        int qq=10;
        const int* pi=&qq;
        //*pi=50;  错 pi有const属性  不能通过pi来修改值(指向的内容不能变)
        qq=100;
        
        //const 修饰指针,则指针为不可变量
        int a = 8;
        int* const p = &a;
        *p = 9; // 正确
        int  b = 7;
        //p = &b; // 错误,p有const属性,p指向的内存地址不能够被改变,但其内容可以改变

  • 相关阅读:
    String类
    Scanner类
    Object类
    接口
    static关键字
    final关键字
    抽象类
    权限修饰符
    方法重写 (Override)
    面向对象思想特征
  • 原文地址:https://www.cnblogs.com/liming19680104/p/13780244.html
Copyright © 2011-2022 走看看