把函數的返回值的類型設定爲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]=''//給字元串寫結尾
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