zoukankan      html  css  js  c++  java
  • const用法

    一、const作用

    二、const用法

    1、修饰一般常量  

      修饰符const可以用在类型说明符前,也可以用在类型说明符后。

    例如: 

      int const x=2; 
      const int x=2; 

    2、修饰常数组

       修饰符const可以用在类型说明符前,也可以用在类型说明符后 

    例如: 

      int const a[5]={1, 2, 3, 4, 5}; 
      const int a[5]={1, 2, 3, 4, 5}; 

    3、修饰常指针 

    ① const int *A;   

      const修饰指向的对象,A可变,A指向的对象不可变 
    ② int const *A;

      const修饰指向的对象,A可变,A指向的对象不可变 
    ③ int * const A; const

      修饰指针A, A不可变,A指向的对象可变 
    ④ const int * const A;

      指针A和A指向的对象都不可变 

    参考资料:c语言中const关键字详解

  • 相关阅读:
    poj 3744 题解
    hdu 1850 题解
    New World
    CSP2019游记
    LOJ6052 DIV
    CF809E Surprise me!
    Luogu4548 歌唱王国
    Luogu4581 想法
    Note 5.26-5.28
    LOJ6519 魔力环
  • 原文地址:https://www.cnblogs.com/amanlikethis/p/3783986.html
Copyright © 2011-2022 走看看