您的位置:首页 > 其它

动态创建二维数组

2017-11-13 15:36 204 查看

利用数组指针

char(*c)[5];
try{c = new char[n][5];}
catch(bad_alloc)
{
cerr<<"Out of Memory"<<endl;
exit(1);
}


其中
c
是一个数组指针,[5]指定的是列数。

利用指针的指针

try
{
char **x = new char *[numberOfRows];
for(int i=0;i<numberOfRows;i++)
x[i] = new char[numberOfColumns];
return true;
}
catch(bad_alloc)
{
return false;
}

//delete
//删除行数组空间
for(int i=0;i<numberOfRows;i++)
delete [] x[i];
//删除行指针
delete []x;
x=NULL;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: