指针的指针 char **p=NULL;
指针的引用 char *&p;//一般作为函数参数使用。
更直观作如下变化。
typedef int* intp;
intp *p1=NULL;
intp &p2=p1;
void testPointReference(char *&pstr)
{
pstr = new char[64];
sprintf(pstr,"I need you!");
}
void testPointReference(char **pstr)
{
*pstr = new char[64];
sprintf(*pstr,"you need me?");
}
int main()
{
char *p1=NULL;//指针
char *&p2=p1;//指针引用。
testPointReference(p1);
cout<<p1<<endl;
testPointReference(&p1);
cout<<p1<<endl; delete []p1;
}
输出结果:I need you!
you need me?