C++进阶:新人易入的那些坑 --1.常量、常指针和指针常量
2024-08-21 12:54:55
声明:以下内容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
}
最新文章
- 关于 python
- bug
- eclipse 技巧
- EasyDropDown – 很棒的下拉菜单 含精美主题
- PHP学习笔记02——简易计算器
- Debian 8 安装 Nvidia 显卡驱动
- mac jdk设置
- MongoDB - MongoDB CRUD Operations
- C#反射的应用【转】
- iOS_数据库3_sqlite3基本操作
- UI设计切忌墨守成规,但改变也须用数据说话
- [模板] 动态树/LCT
- Java代码实现封装多级树结构对象
- 大数据开发主战场hive (企业hive应用)
- 搞懂ES6的import export
- jemter模拟高并发访问(亲测ok)
- 详解如何进行第三方App接入微信登录
- 【java】解析java网络
- 小程序:pages/index/index/出现脚本错误或未正确调用Page()
- eclipse查看源码失败总结
热门文章
- 自相关系数 ACF与偏自相关系数PACF,拖尾和截尾
- windows系统安装gcc编译器----c/c++语言编译器
- 使用第三方工具Thumbnailator动态改变图片尺寸
- JavaScript的数组和循环
- webbrowser设置为相应的IE版本
- HG奋斗赛B[20190429]
- (二)ORB描述子提取源码思路与实现
- pythonのdjango select_related 和 prefetch_related()
- spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,guava限流,定时任务案例, 发邮件
- onscroll 元素滚动事件