char型函数返回值的类型?
把函数的返回值的类型设置为char类型的指针就可以了。
例如:char* MultMatrix( )
实例:
#include <iostream>
using namespace std;
char* MultMatrix( )
{
char*M = new char[4];
M[0]='a';
M[1]='b';
M[1]='c';
M[3]='d';
M[3]='\0';//给字符串写结尾
cout << M[0] << " " << M[1] << endl;//输出返回前的数组
cout << M[2] << " " << M[3] << endl;
return M;
}
int main()
{
char *M = MultMatrix();
cout << M[0] << " " << M[1] << endl;//输出返回后数组
cout << M[2] << " " << M[3] << endl;
delete[] M;
return 0;
}
运行结果:
a b
c d
a b
c d
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有