c++ --记录


使用new时,不建议这样写,只是一个小小test。

注意:Get(char **p) 函数不能为Get(char *p)。

 1 //指针原来为None,改变指针
 2 void Get(char **p)
 3 {
 4     *p=new char[100];
 5 }
 6 void test()
 7 {
 8     char *str=nullptr;
 9     Get(&str);
10     strcpy(str,"helloworld");
11 
12     cout<<str<<endl;
13     delete [] str;
14     str=nullptr;
15     cout<<str<<endl;
16 }
17 //输出:helloworld
原文地址:https://www.cnblogs.com/cygalaxy/p/7491571.html