函数传指针和传引用

#include<iostream>
using namespace std;

//测试
//传引用:改变值,相当于别名
//传指针:改变传递进去的指针对应的地址的值
//返回指针:可以修改对应指针对应地址处的值
int* test(int &c, int *d)
{
	int b[4] = {1,2,3,4};
	c = 5;
	d[2] = 99;
	return b;
}


int main()
{

	int *a = NULL;
	int c;
	int d[4] = {2,3,4,5};
	a = test(c,d);
	cout<<a[0]<<c<<d[2]<<endl;//1,5,99
	return 0;
}





posted @ 2013-04-11 19:56  夏至冬末  阅读(156)  评论(0编辑  收藏  举报