int iNumRows = <number of rows>;
int iNumCols = <number of columns>;
int iNumElements = iNumRows * iNumCols;
int* aaiArray = new int*[iNumRows];
aaiArray[0] = new int[iNumElements];
memset(aaiArray,0,iNumElements*sizeof(int));
for (iRow = 1; iRow < iNumRows; iRow++)
{
aaiArray[iRow] = &aaiArray[0][iNumCols*iRow];
}
// deallocation
delete[] aaiArray[0];
delete[] aaiArray;
关于二维数组的动态内存分配的一个比较好的方法
最新推荐文章于 2021-07-08 04:11:16 发布