关于const于pointer
来源:互联网 发布:蛋糕西点软件 编辑:程序博客网 时间:2024/05/01 14:43
这段时间在复习C++基础知识,会不定期写一些重要的总结,算是这段时间学习过程。
1、关于const与pointer
A、指向const的pointer(指针常量—是指对于指针来说,指向的是常量,实际是不是常量,并不一定)
eg:int age = 23;
int num = 100;
const int * pAge = &age;
*pAge = 50; // 非法的,不能使用
age = 50; // 正确的
pAge = # // 正确的。
注意:pAge的声明并不意味着它指向的值实际上就是一个常量,只是意味着对pAge而言,这个值是一个常量,并且pAge自己不是一个常量。
B、将const变量的地址赋给指向const的pointer(指针常量)
eg: const double PI = 3.141592;
double money = 20.5;
const double *p_PI = Π
p_PI = &money;// OK
C、int age = 21;(常量指针—指针本身是常量)
int sloth = 3;
int * const pointer = &age;
*pointer = 100; // 正确
Pointer = &sloth;// 错误
D、double trouble = 2.65; (指针常量指针)
const double * const stick = &trouble;
*stick = 3.62; // 错误
Stick = &money; // 错误
int num = 15;
const int age = 22;
int * pointer =#
*pointer = 20;
//pointer = &age; //无法从“const int *__w64 ”转换为“int *”
//不能将常量赋给一个变量
*pointer = 25;
const int * conPointer = #
//*conPointer = 62; //指针常量
conPointer = &age;
//*conPointer = 26;
int * const pointerCon = #
*pointerCon = 45;
//pointerCon = &age;//常量指针
//int * const pointerCon1 = &age;//无法从“const int *__w64”转换为“int *const”
*pointerCon = 52;
cout<<"argc:"<<argc<<endl;
cout<<"argv[]:"<<*argv<<endl;
- 关于const于pointer
- Const & Pointer
- const & Pointer
- const pointer
- const && pointer
- const pointer
- Pointer to Const & const pointer
- const pointer 和pointer const
- const pointer(const指针)
- pointer and const
- const pointer的读法
- const pointer and array
- const,template,pointer,virtual
- Pointer and Const
- const And pointer
- 关于pointer
- const修饰的pointer用法
- typedef和const pointer定义
- 配置Asp.net Ajax Control Toolkit
- PHP程序加速探索之压缩输出gzip
- DataColumn 与Xml data type转换。
- 利用SCR文件给注册表解锁
- COM实现取outlook地址簿
- 关于const于pointer
- SQL 2005 体验版 基本安装和使用 (2)
- SMS2003 DB中查询关于patch部署的信息
- HTTP协议中的Tranfer-Encoding:chunked编码解析
- 但求谁可留住这一生
- VS快捷键集锦
- VC++文本编辑器使用
- December 2007
- datatable的创建,插入列,插入行,排序