Pointer to Const & const pointer
来源:互联网 发布:傅里叶变换算法 编辑:程序博客网 时间:2024/05/15 14:41
这是c++语法中比较绕的一个概念,也是笔试面试中经常会考的知识点。 c++你为什么是c++啊?
下面的内容摘自 Thinking in C++ Chapter 8 Constants
Pointer to const
这有两种定义形式
const int* u;
Starting from the identifier, we read “u is a pointer, which points to a const int.”
int const* v;
the way it actually reads is “v is an ordinary pointer to an int that happens to be const.”
都表示了指向的int是不能改变的。
const pointer
int d = 1;
int* const w = &d;
Now it reads: “w is a pointer, which is const, that points to an int.”
Because the pointer itself is now the const, the compiler requires that it be given an initial value that will be unchanged for the life of that pointer. 因为w是常量,所以一定是要初始化的。
const pointer to const
这个其实前两种的合体。
int d = 1;
const int* const x = &d; // (1)
int const* const x2 = &d; // (2)
Now neither the pointer nor the object can be changed
- Pointer to Const & const pointer
- Const & Pointer
- const & Pointer
- const pointer
- const && pointer
- const pointer
- const pointer 和pointer const
- const pointer(const指针)
- pointer and const
- 关于const于pointer
- const pointer的读法
- const pointer and array
- const,template,pointer,virtual
- Pointer and Const
- const And pointer
- 常量指针(const pointer)和指向常量的指针(pointer to const)
- ICCAVR软件编译时出现found pointer to const unsigned char expected pointer to unsigned char
- const修饰的pointer用法
- 暂停和恢复cocos2d内库的使用代码
- 什么是little-endian和big-endian,如何用程序判断
- 数据库ACID 理论
- 禁掉inactive code colorize
- Maven最佳实践:版本管理
- Pointer to Const & const pointer
- vsftpd配置文件讲解
- Android开发者应该深入学习的10个开源应用项目
- 常见的vsftpd日志解决方案及FTP数字代码的意义
- SendMessage 和 PostMessage 的区别
- deb包 安装和删除
- 开博第一篇~~
- c++builder对身份证信息校验说明
- php中session过期时间设置