您的位置:首页 > 编程语言 > C语言/C++

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;
}


数组的引用和指针的引用非常类似,因为数组名本身也是一个地址;对二维数组而言,我们传参的方式有三种
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: