const int * 与int const * 与int * const的区别
来源:互联网 发布:手机版淘宝店招怎么装 编辑:程序博客网 时间:2024/05/25 19:58
一、指向常量的指针
定义形式:const类型 * 指针名;
不能通过指针修改地址里的值。
const int * 与int const * 是一个意思。
egg:
int i = 0x123;int k = 0x12;const int *p = NULL;p = &i;printf("%0x\n",p);printf("%0x\n",*p);//*p = 0x234; //不能赋值 错误p = &k;//但是可以修改其地址printf("%0x\n",p);printf("%0x\n",*p);getchar();getchar();getchar();
二、常量指针
定义形式:类型*const 指针名;
egg:
int i = 0x123;int k =0x23;int * const p = &i;//在这里赋地址//p = &i; //错误写法,应该最开始就赋值*p = 0x12;//p = &k;//错误不能修改地址printf("%0x\n",*p);
小结:
前置const不能通过指针改变地址内的值(在*号前)*p=???;
后置const不能改变地址,也就是不能从新给指针赋值(在*号后)p=???;
0 0
- const int * 与int const * 与int * const的区别
- const int *与int *const 的区别
- const int * 与 int *const区别
- const int * 与 int *const
- const int *a与int *const a,const int *const a的区别
- const int *a与int *const a,const int *const a的区别
- const int *pi与int *const pi的区别
- const int *p与int *const p的区别
- const int *pi与int *const pi的区别
- const int a与int const a的区别
- const int *a 与int *const a的区别
- const int *p与int *const p的区别
- const int *p与int * const p的区别
- int const *pci 与 int *const pci的区别
- const int* p与int *const p的区别
- C/C++_ const int * 与 int *const的区别
- const int *p与int *const p的区别
- const int *p与int *const p的区别
- 两个栈实现队列 两个队列实现栈
- UIGestureRecognizer手势识别器
- 数据卫士DG
- mysql数据格式问题
- Java多态性轻松理解
- const int * 与int const * 与int * const的区别
- 简单的Fragment使用(包括横竖屏)
- android上传图片到服务器(使用base64字节流的形式通过 AsyncHttpClient框架
- 睡觉的诀窍
- bzoj1619【Usaco2008 Nov】Guarding the Farm 保卫牧场
- 04-封装BaseServlet和设置全站请求编码过滤器EncodingFilter
- 【Opencv初学者笔记】-vs2010的配置和简单例程demo
- 5-26 Population (35分) -- 待解决
- oracle linux yum update加速