how to find 2d array size in c++

后端 未结 9 768
余生分开走
余生分开走 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 12:51

    Here is one possible solution of first part

    #include
    
    using namespace std;
    int main()
    {
        int marks[][4] = {
                          10, 20, 30, 50,
                          40, 50, 60, 60,
                          10, 20, 10, 70
                         };
    
    int rows =  sizeof(marks)/sizeof(marks[0]);
    int cols = sizeof(marks)/(sizeof(int)*rows);
    
    
        for(int i=0; i

提交回复
热议问题