三维数组按照一维数组使用

#include <iostream>

using namespace std;

int main(){
        int a[2][3][4]={
                {
                        { 0, 1, 2, 3},
                        { 4, 5, 6, 7},
                        { 8, 9,10,11}
                },
                {
                        {12,13,14,15},
                        {16,17,18,19},
                        {20,21,22,23}
                }

        };

        int *pInt=&a[0][0][0];

        for(int i=0; i<2; i++){
                for(int j=0; j<3; j++)
                        for(int k=0; k<4; k++){
                                cout<< a[i][j][k] <<"  ";
                        }

        }

        cout<<endl<<endl;

        for(int index=0; index<2*3*4; index++)
        cout<<pInt[index]<<"  ";

        cout<<endl<<endl;

        return 0;
}
 

猜你喜欢

转载自blog.csdn.net/eloudy/article/details/121763062