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