const关键字

Posted 大飞歌

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了const关键字相关的知识,希望对你有一定的参考价值。

1》修饰基本类型变量(使其只读)

 

2》修饰指针:

  ①、int const *p或者const int *p;

    *p是只读的,不可以通过指针修改,可以通过变量修改;

  ②、int * const p;

    const将p变为只读数据

  ③、const int * const p;

     const将p和*p都变为只读数据

以上是关于const关键字的主要内容,如果未能解决你的问题,请参考以下文章

const关键字与指针

C++const关键字详解 && volatile关键字了解

const关键字与指针

C++ 类中的const关键字

const关键字与数组指针

const关键字到底该怎么用