c++ 函数返回指针 及用法
#include<string> #include<iostream> using namespace std; string fun1(int a) { string str = "a"; return str; } char* fun2(int a) { char *p = new char[2]; p[0] = 'a'; p[1] = '\0'; return p; } void main() { cout<<fun1(4)<<endl; char *p = fun2(4); cout<<p<<endl; delete [] p; }