关于指针的传值与传址

void change(int *p)
{
	*p = 100;
}
void change2(int **p)
{
	*p = new int(200);
}
void change3(int *&p)
{
	p = new int(300);
}
int main()
{
	int a = 1;
	int *b = new int(2);
	change(&a); // a  = 100
	change(b);  //*b  = 100
	cout<<a<<'\t'<<*b<<endl;
	delete b;
	b = NULL;
	change2(&b);//*b = 200
	cout<<a<<'\t'<<*b<<endl;
	
	delete b;
	b = NULL;
	
	change3(b); //*b = 300
	cout<<a<<'\t'<<*b<<endl;
	delete b;
	b = NULL;
	return 1;
}
posted on 2015-03-25 10:54  qinfengxiaoyue  阅读(476)  评论(0编辑  收藏  举报