Multi-dimensional array and pointers in C++?

后端 未结 6 1517
悲哀的现实
悲哀的现实 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条回答
  •  星月不相逢
    2020-12-20 10:04

    This is how you do it:

    int (*x)[5] = new int[7][5] ;
    

    I made the two dimensions different so that you can see which one you have to use on the lhs.

提交回复
热议问题