how to find 2d array size in c++

后端 未结 9 860
余生分开走
余生分开走 2020-12-23 12:14

How do I find the size of a 2D array in C++? Is there any predefined function like sizeof to determine the size of the array?

Also, can anyone tell me h

9条回答
  •  余生分开走
    2020-12-23 13:06

    Use an std::vector.

    std::vector< std::vector > my_array; /* 2D Array */
    
    my_array.size(); /* size of y */
    my_array[0].size(); /* size of x */
    

    Or, if you can only use a good ol' array, you can use sizeof.

    sizeof( my_array ); /* y size */
    sizeof( my_array[0] ); /* x size */
    

提交回复
热议问题