how to define, pass, and walk through the different dimensions of an array : multi dimension array « Array « C++ Tutorial

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » Array » multi dimension array 
4.4.9.how to define, pass, and walk through the different dimensions of an array
#include <iostream>
using namespace std;

void vdisplay_results(char carray[][3][4]);
  
  char cglobal_cube[5][4][5]{
                {
                  {'1','1','1','1','1'},
                  {'2','2','2','2',' '},
                  {'3','3','3','3',' '},
                  {'4','4','4',' ',' '},
                },
                {
                  {'1','1','1','1','1'},
                  {'2','2','2','2',' '},
                  {'3','3','3','3',' '}
                },
                {
                  {'1','1','1','1','1'},
                  {'2','2','2','2',' '}
                },
                {
                  {'1','1','1','1','1'},
                  {'2','2','2','2',' '},
                  {'3','3','3','3',' '},
                  {'4','4','4',' ',' '},
                },
                {
                  {'1','1','1','1','1'},
                  {'2','2','2','2',' '},
                  {'3','3','3','3',' '},
                  {'4','4','4',' ',' '},
                }
};

int imatrix[4][3]={ {1},{2},{3},{4} };
  
int main( )
{
 int irow_index, icolumn_index;
 char clocal_cube[2][3][4];

 cout << "sizeof clocal_cube         = "<< sizeof(clocal_cube)           << "\n";
 cout << "sizeof clocal_cube[0]      = "<< sizeof(clocal_cube[0])        << "\n";
 cout << "sizeof clocal_cube[0][0]   = "<< sizeof(clocal_cube[0][0])     << "\n";
 cout << "sizeof clocal_cube[0][0][0]= "<< sizeof(clocal_cube[0][0][0])  << "\n";

 vdisplay_results(clocal_cube);

 cout << "cglobal_cube[0][1][2] is     = " << cglobal_cube[0][1][2<< "\n";
 cout << "cglobal_cube[1][0][2] is     = " << cglobal_cube[1][0][2<< "\n";

 for(irow_index=0; irow_index < 4; irow_index++) {
   for(icolumn_index=0; icolumn_index < 5; icolumn_index++)
     cout << cglobal_cube[0][irow_index][icolumn_index];
   cout << "\n";
 }


 for(irow_index=0; irow_index < 4; irow_index++) {
   for(icolumn_index=0; icolumn_index < 5; icolumn_index++)
     cout << cglobal_cube[4][irow_index][icolumn_index];
   cout << "\n";
 }

 cout << "\nprint all of imatrix\n";
 for(irow_index=0; irow_index < 4; irow_index++) {
   for(icolumn_index=0; icolumn_index < 3; icolumn_index++)
     cout << imatrix[irow_index][icolumn_index];
   cout << "\n";
 }

 return (0);
}
  
void vdisplay_results(char carray[][3][4])
{
    cout << "sizeof carray           =" << sizeof(carray<< "\n";
    cout << " sizeof  carray[0]      =" << sizeof(carray[0]) << "\n";
    cout << " sizeof  cglobal_cube   =" << sizeof(cglobal_cube<< "\n";
    cout << " sizeof cglobal_cube[0] =" << sizeof(cglobal_cube[0])
                                        << "\n";
}
4.4.multi dimension array
4.4.1.Declare a two-dimension array
4.4.2.Initialize a two-dimension array
4.4.3.Creating A Multidimensional Array
4.4.4.Initializing multidimensional arrays
4.4.5.Search a two-dimension array
4.4.6.Use nested for loop to display the two dimesional array
4.4.7.Using pointer notation with a multidimensional array
4.4.8.Fill a two dimensional integer array element by element
4.4.9.how to define, pass, and walk through the different dimensions of an array
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.