阅读程序,写出运行结果。
#include
using namespace std;
void test1( int *a1 )
{ a1 = new int( 5 );
cout << "*a1 = " << *a1 << endl;
}
void test2(int * & a2)
{ a2 = new int( 5 );
cout << "*a2 = " << *a2 << endl;
}
int main()
{ int *p = new int( 1 );
test1( p );
cout << "test1: *p1 = " << *p << endl;
test2( p );
cout << "test2: *p2 = " << *p << endl;
}
test1()不改变实参,而test2却改变实参,二者有什么区别呢?