声明:以下内容B站/Youtube学习笔记,https://www.youtube.com/user/BoQianTheProgrammer/ Advanced C++.

 /*
why use const
a)Guards against inadvertent write to the variable
b)Self documenting
c)Enables compiler to do more optimization,making code tighter,faster
d)const means the variable can be put in ROM
*/
//const
// A compile time constraint that an object can not be modified int main()
{
const int i = ;
//i = 7; wrong
//如何修改i的值呢?
const_cast<int&>(i) = ; int j;
static_cast<const int&>(j) = ;//wrong,此时j被转成const const int *p1 = &i;//data is const,pointer is not
p1++;
int * const p2;//pointer is const,data is not
const int* const p3;//data and pointer are both const int const *p4 = &i;
const int *p4 = &i;
//If const is on the left of *,data is const
//If const is on the right of *,pointer is const
}

最新文章

  1. 关于 python
  2. bug
  3. eclipse 技巧
  4. EasyDropDown – 很棒的下拉菜单 含精美主题
  5. PHP学习笔记02——简易计算器
  6. Debian 8 安装 Nvidia 显卡驱动
  7. mac jdk设置
  8. MongoDB - MongoDB CRUD Operations
  9. C#反射的应用【转】
  10. iOS_数据库3_sqlite3基本操作
  11. UI设计切忌墨守成规,但改变也须用数据说话
  12. [模板] 动态树/LCT
  13. Java代码实现封装多级树结构对象
  14. 大数据开发主战场hive (企业hive应用)
  15. 搞懂ES6的import export
  16. jemter模拟高并发访问(亲测ok)
  17. 详解如何进行第三方App接入微信登录
  18. 【java】解析java网络
  19. 小程序:pages/index/index/出现脚本错误或未正确调用Page()
  20. eclipse查看源码失败总结

热门文章

  1. 自相关系数 ACF与偏自相关系数PACF,拖尾和截尾
  2. windows系统安装gcc编译器----c/c++语言编译器
  3. 使用第三方工具Thumbnailator动态改变图片尺寸
  4. JavaScript的数组和循环
  5. webbrowser设置为相应的IE版本
  6. HG奋斗赛B[20190429]
  7. (二)ORB描述子提取源码思路与实现
  8. pythonのdjango select_related 和 prefetch_related()
  9. spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,guava限流,定时任务案例, 发邮件
  10. onscroll 元素滚动事件