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;
}

 

posted on 2015-07-09 16:56  雨渐渐  阅读(263)  评论(0编辑  收藏  举报

导航