How do i declare a 2d array using new?

来源:互联网 发布:js 过去选中的radio 编辑:程序博客网 时间:2024/06/03 19:29

A dynamic 2D array is basically an array of pointers to arrays. You should initialize it using a loop, like this:

int** ary = new int*[rowCount];for(int i = 0; i < rowCount; ++i)    ary[i] = new int[colCount];

The above, for colCount= 5 and rowCount = 4, would produce the following:

enter image description here

shareedit
原创粉丝点击