1. 程式人生 > >C++ 多維陣列練習

C++ 多維陣列練習

int ia[3][4];
    int cnt = 0;
    for (auto &row : ia){
        for (auto &col : row){
            col = cnt++;
            cout<<col<<" ";
        }
    }
    cout<<endl;
    
    int (*p)[4] = ia;
    cout<<p<<" "<<*(p+1)<<" "<<p[1]<<" "<<&ia[1]<<endl;
    
    for (int (&p)[4] : ia){
        for(int q : p)
            cout<<q<<" ";
    }
    
    for (int (*p)[4] = ia; p != ia+3; ++p){
        int *a = *p;
        for (int *q = a; q != a+4; ++q){
            cout<<*q<<" ";
        }
        
        for (int i=0; i<4; ++i){
            cout<<a[i]<<" ";
        }
    }
充分理解,多維陣列是陣列的陣列;理解每層指標的具體含義!