int *const p与int const *p的区别简析
来源:互联网 发布:网络视频监控方案 编辑:程序博客网 时间:2024/06/03 21:50
在指针的学习过程中我们有时可能看到*const p与const *p,但是有时很容易搞忘它们区别;下面我就通过两幅图做一个小小的说明。
要搞清楚int *const p与int const *p的区别,我们先确定2个定义。第一个是const,const就是一个修饰符,让变量或者对象的值不能被修改;第二个是指针的实质,指针的实质就是确定的一个来几下被指对象的地址的变量。 那么我们接下来就来分析int *const p与int const *p。如图所示,*const p ,它表示在P记下被指对象后,它有一个地址值ffc1,即在ffc2这个内存地址上有一个ffc1,然而之后有const的修饰,那么ffc2上记录的ffc1这个值在整个程序中i不能被改变了,也就是输出的一定是a1的值,不能被再次赋值了。像图1一样,p输出的值还是a1的值。
对int const *P ,实质上可以看着或者写出const int *p,那么这样我们就可以随时给p赋上一个新的地址,而const也只是对这新地址的值定义,要求这个地址值不能改变,(事实上,一个只确定了坑定不会改变的,比如,这谢了个5,这个5自己坑定不会自己变成6,所以const 就没有多大用用了),我们还是可以再次给P赋一个新的地址,像图二表示的一样*p输出的值就改变了。
0 0
- const int *p与int *const p的区别
- const int *p与int *const p的区别
- const int *p与int * const p的区别
- const int* p与int *const p的区别
- const int *p与int *const p的区别
- const int *p与int *const p的区别
- const int *p与int *const p的区别
- const int *p与int *const p的区别
- 关于const int *p与 int *const p的区别
- int *const p与int const *p的区别简析
- int * const p 与int const *p或者const int *p的区别
- const int *p,int *const p区别
- const int *p,int *const p区别
- const int *p,int *const p区别
- int * const p 与 const int *p
- int *const p 与 const int *p
- const int *p与int *const p
- int const *p与int *const p区别
- lufylegend引擎 rpg开发之2D地图的碰撞检测
- Android SDK更新 及 所有SDK文件共享
- 产品模式总结
- OpenCv3.0+SVM的使用心得(一)
- ArrayList源码剖析
- int *const p与int const *p的区别简析
- 第十六题
- 无法安装 Visual Studio 2010 Service Pack 1,因为此计算机的状态不支持
- _stdcall ,_cdecl,__fastcall 深入解析
- java基础1:异常
- JS验证控件jQuery Validate
- windows下获取mac地址的两种方法
- virtual析构函数
- P51.18(判断一正整数n是否同时含有奇数和偶数。)