Multi-dimensional array and pointers in C++?

后端 未结 6 1510
悲哀的现实
悲哀的现实 2020-12-20 09:35
int *x = new int[5]();

With the above mentality, how should the code be written for a 2-dimensional array - int[][]?

i         


        
6条回答
  •  萌比男神i
    2020-12-20 10:02

    You can do the initializations separately:

    int **x = new int*[5];
    for(unsigned int i = 0; i < 5; i++)
        x[i] = new int[5];
    

提交回复
热议问题