C++ const和指针笔记

C++ const和指针笔记

2021-3-12
zhuhongxi

  • 方法一:
 1. const int p; 
 2. const int* p; 
 3. int const* p;
 4. int * const p;
 5. const int * const p;
 6. int const * const p;
 7. 
 第一种是常量整数,没什么好说的。后面五种是指针,有一个简便的办法记忆。
 
 从右往左读,遇到p就替换成“p is a ”遇到*就替换成“point to”。
 
 比如说2,读作:p is a point to int const.p是一个指向整型常量的指针。
 3读作:p is a point to const int.意思跟②相同。
 4读作:p is a const point to int.p是一个常量指针,指向整型。
 5读作:p is a const point to int const.
 6读作:p is a const point to const int.
 5和6的意思相同,p都是常量指针,指向整型常量。
  • 方法二:
把const读作常量,把星号*读作指针

比如:

int * const p 就是指针常量(const pointer),指针的地址是常量

int const * p 就是常量指针(pointer to const),指向的量是常量

以此类推...
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坂田民工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值