当前位置:柔美女性网 >

绿色生活 >心理 >

char怎样设置返回值

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

标签: char 返回值 设置
  • 文章版权属于文章作者所有,转载请注明 https://rmnxw.com/lvse/xinli/1z60x6.html