c++ const关键字

  • define与const的区别

1.define作用在预处理时,是简单地字符替换

2. const作用在编译时,具有类型检查的功能

3. const必须进行初始化

  • 常量指针与指针常量
 1 #include <iostream>
 2 
 3 using std::endl;
 4 using std::cout;
 5 
 6 int main()
 7 {
 8      int a = 100;
 9      const int *pa = &a;
10      int * const pb = &a;  
     return 0;
11 }
  • 小结:

const int *pa = &a;-->常量指针

可以改变指针指向,不能改变所指变量的值。

int * const pb = &a;

不能改变指针指向,可以改变所指变量的值。

 

posted on 2017-06-29 09:56  李兆祥  阅读(142)  评论(0)    收藏  举报

导航