心理

當前位置 /首頁/完美生活/心理/列表

char怎樣設定返回值

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]=''//給字串寫結尾

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

TAG標籤:char 返回值 設定 #