C/C++对数组的引用——指向指针的指针和指针引用
2012-08-23 23:43
435 查看
http://blog.csdn.net/anye3000/article/details/6578262
数组的引用和指针的引用非常类似,因为数组名本身也是一个地址;对二维数组而言,我们传参的方式有三种
#include <iostream> using namespace std; void main() { int a = 10; int **pTest = new int*; int *pSec = &a; pTest = &pSec; *pTest = pSec; cout<<*pTest<<endl; cout<<pSec<<endl; cout<<**pTest<<endl; //修改一个指针的值 *pSec = 100; cout<<**pTest<<endl; //测试引用 int &b = a; cout<<b<<endl; b = 1000; cout<<a<<' '<<b<<endl; //int *&pRef = &a;//error. int*pRef = &a; int* &pNef = pRef; //修改变量a的值 *pRef = 2000;//通过指针修改a的值 cout<<a<<endl; //a的值被修改 *pNef = 3000; cout<<a<<endl;//通过指针的引用修改变量a的值 cout<<pRef<<endl; }
数组的引用和指针的引用非常类似,因为数组名本身也是一个地址;对二维数组而言,我们传参的方式有三种
相关文章推荐
- 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象, const 指针和指向 const 对象的指针, const 对象的引用
- C++引用数组,函数指针,函数指针数组,结构体数组等学习
- C++入门学习:虚析构、构造中不能实现多态、基类指针指向派生类数组的弊端
- C++编程实例-数组、指针及引用
- C++指针数组和指向指针的指针
- 【C/C++】指向数组的指针
- C++:指向数组的智能指针scoped_array组件的使用
- C++指针与引用以及数组
- 彻底搞清C/C++中一维数组,二维数组,指针,数组指针和指针数组以及指向指针的指针,行地址和列地址之间的关系
- [C++] 引用和指向指针的引用
- c++的中的指向类的指针和引用的比较
- C++中 常量引用、指向常量的指针、常量指针的区别
- 在c++中使用指向数组的引用
- 动态创建二维vector数组 C和C++ 及指针与引用的区别
- more effective c++ 第一章读书笔记: 指针,引用,c++类型转换,多态数组,默认构造函数
- lua使用C++的指针、引用、值、数组
- C++ 数组引用传递与指针传递
- C++ 多态问题:为什么不直接用子类引用子类,而是用父类指针指向子类
- 对C++中指向数组类型的指针的理解