这里要用到二级指针,或者是引用,不然值不能传回去!
要是直接用
void test(int* n);
那么子函数得到的是*n的副本,在函数内n指向的内同改变,但是这个值传不回主函数!
#include <iostream>
void test(int** n);
int main()
{
int *n;
test(&n);
system("pause");
return 0;
}
void test(int** n)
{
int* a = new int;
*a = 5 ;
*n = a;
}