[转]const指针与指向const的指针
经常忘记,保存一下..
#include <iostream> using namespace std; int main(int argc, char *argv[])
{
int a=;
int b; /*定义指向const的指针(指针指向的内容不能被修改)*/
const int* p1;
int const* p2; /*定义const指针(由于指针本身的值不能改变所以必须得初始化)*/
int* const p3=&a; /*指针本身和它指向的内容都是不能被改变的所以也得初始化*/
const int* const p4=&a;
int const* const p5=&b; p1=p2=&a; //正确
*p1=*p2=; //不正确(指针指向的内容不能被修改) *p3=; //正确
p3=p1; //不正确(指针本身的值不能改变) p4=p5;//不正确 (指针本身和它指向的内容都是不能被改变)
*p4=*p5=; //不正确(指针本身和它指向的内容都是不能被改变) return ;
}
引用地址: http://hi.baidu.com/study_cs/item/c4c469cb35bd890bac092f37
[转]const指针与指向const的指针的更多相关文章
- 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象, const 指针和指向 const 对象的指针, const 对象的引用
[源码下载] 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象, const 指针和指向 const 对象的指针, con ...
- const 指针与指向const的指针
最近在复习C++,指针这块真的是重难点,很久了也没有去理会,今晚好好总结一下const指针,好久没有写过博客了,记录一下~ const指针的定义: const指针是指针变量的值一经初始化,就不可以改变 ...
- const指针和指向常量的指针
先看下面六种写法: . const int p; . const int *p; . int const* p; . int * const p; . const int * const p; . i ...
- Const指针 、 指向const的指针 、引用、指针
1. const指针和 指向const的指针 指向const的指针: 不允许通过指针来改变其指向的const值 const double *cptr *cptr = 42; // error! 指针 ...
- 辨析 const指针 和 指向常量的指针
辨析以下几种指针p的定义. ; int *p = &tmp; const int *p = &tmp; int const* p = &tmp; int * const p = ...
- 【转】const int *p和int * const p的区别(常量指针与指向常量的指针)
[转]作者:xwdreamer 出处:http://www.cnblogs.com/xwdreamer 对于指针和常量,有以下三种形式都是正确的: const char * myPtr = &am ...
- const对象,指向const对象的指针 和 const 指针
const对象: const对象声明时必须赋初值,该值在编译阶段确定,不可在程序中修改. const修饰符既可放在类型名前也可放在类型名后,通常放在类型名前.不过放在类型名后易于理解. const i ...
- const指针和指向const的指针
int *const p=&a; 这是const指针,这种指针必须在定义时就给出它所指向的地址,否则会error:uninitialized const 'p'.const指针的指针本身是co ...
- 速记const 指针与指向const的指针
指向const的指针.它的意思是指针指向的内容是不能被改动的.它有两种写法. ` const int* p; (推荐) int const* p;` 再说const指针.它的意思是指针本身的值是不能被 ...
随机推荐
- CodeChef February Challenge 2018 Broken Clock (三角函数推导 + 矩阵快速幂)
题目链接 Broken Clock 中文题面链接 令$cos(xα) = f(x)$ 根据三角函数变换公式有 $f(x) = \frac{2d}{l} f(x-1) - f(x-2)$ 我们现在 ...
- 磁盘镜像工具Guymager
磁盘镜像工具Guymager 在数字取证中,经常需要对磁盘制作镜像,以便于后期分析.Kali Linux提供一款轻量级的磁盘镜像工具Guymager.该工具采用图形界面化方式,提供磁盘镜像和磁盘克 ...
- SQLite中的内连接简化技巧
SQLite中的内连接简化技巧 在SQLite中,通过内连接可以将两个表通过条件表达式关联起来,构成一个新记录集或视图.形式如下: SELECT ... FROM t1 JOIN t2 ON ...
- POJ 2155 Matrix(树状数组+容斥原理)
[题目链接] http://poj.org/problem?id=2155 [题目大意] 要求维护两个操作,矩阵翻转和单点查询 [题解] 树状数组可以处理前缀和问题,前缀之间进行容斥即可得到答案. [ ...
- 安装php5.4.10时, 错误:‘gdIOCtx’ 没有名为 ‘data’ 的成员
安装php5.4.10时, 错误:‘gdIOCtx’ 没有名为 ‘data’ 的成员 在安装php时,报如下错误 In file included from /kk/php-5.4.0/ext/gd/ ...
- linux 内核学习
http://www.cnblogs.com/tolimit/category/697314.html
- applicationContext.xml文件如何调用外部properties等配置文件
只需要在applicationContext.xml文件中添加一行: <!-- 导入外部的properties文件 --> <context:property-placeholder ...
- Ubuntu system zabbix-server-3.x install documentation
Installing repository configuration package wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/ ...
- jstat命令的使用及VM Thread分析
http://www.javatang.com/archives/2017/10/20/12131956.html 前面提到了一个使用jstack的shell脚本,通过命令可以很快地定位到指定线程对应 ...
- vscode - 使用Settings进行同步扩展以及配置信息等
1. 创建token(记住要复制上面的token): https://github.com/settings/tokens. 2. 创建gist id https://gist.github.com/ ...