zoukankan      html  css  js  c++  java
  • C++程序设计入门 之常量学习

    常量:

    常量的定义格式:const datatype CONSTANTNAME = VALUE

    常量的命名规范:符号常量(包括枚举值)必须全部大写并用下划线分隔单词 例如:MAX_ITERATIONS, COLOR_RED, PI

    常量与指针:

    two features of a pointer(指针的两个属性):

     pointer variable (指针变量本身)

     data that the pointer points to (指针变量所指向的数据) 

    常量和指针的组合:

    1.常量指针/常指针:

    特征:指针所指向的内容不可以通过指针的间接引用(*p)来改变。

    const int* p1; const int x = 1;
     p1 = &x;      // 指针p1 的 类型是(const int*)
    *p1 = 10;     // Error!

    2.指针常量:

     特征:指针本身的内容是个常量,不可以改变。

    int x = 1, y = 1; 
    int* const p2 = &x; // 常量p2 的 类型是(int*)
    *p2 = 10;     // Okay! x=10
    p2 = &y; // Error! p2 is a constant
  • 相关阅读:
    css变量
    es6的this指向
    Java面试题(包装类)
    moment笔记
    Class
    CSS斜切角
    Element.getBoundingClientRect()
    Do not mutate vuex store state outside mutation handlers.
    antd不想写那么多option怎么办
    解析URL参数
  • 原文地址:https://www.cnblogs.com/wjc2021/p/10665583.html
Copyright © 2011-2022 走看看