1. 程式人生 > >new和delete建立和銷燬二維陣列

new和delete建立和銷燬二維陣列

int** new_arry(int row, int col)
{//建立arry【row】【col】
	int**arry = (int**)new int*[row];
	for (int i = 0;i < row;i++)
	{
		arry[i] = new int[col];
	}
	for (int i = 0;i < row;i++)
		for (int j = 0;j < col;j++)
			arry[i][j] = 1;
	return arry;
}

void delete_arry(int**arry, int row, int col)
{//銷燬arry【row】【col】
	for (int i = 0;i < row;i++)
	{
		delete[]arry[i];
	}
	delete[]arry;
}

在這裡插入圖片描述