Week# 10
Multidimensional Arrays
Dr Taimur Ahmed
Department of IT & CS, PAF-IAST
Lecture# 27
Three dimensional (3D) Array
 A 3D array is a multidimensional array used to store 3-dimensional data
 In other words, a 3D array is an array of arrays
 To visualize a 3D array, consider two 2D arrays when they are
combined, they form a 3D array
3D Array
| 3
Lecture# 27 - 3D Array
a[0][0] a[0][1] a[0][2] a[0][3]
a[1][0] a[1][1] a[1][2] a[1][3]
Row 0
Column 0 Column 1 Column 2 Column 3
2x4
Row 1
b[0][0] b[0][1] b[0][2] b[0][3]
b[1][0] b[1][1] b[1][2] b[1][3]
Row 0
Column 0 Column 1 Column 2 Column 3
Row 1
2x4
 Use three declarators in definition:
Data_type Name_of_Array[Array_Number][ROW][COLUMN];
 First declarator is number of arrays; second is number of rows; third is
number of columns
const int ARR = 2, ROWS = 4, COLS = 3;
int exams[ARR][ROWS][COLS];
3D Array – Declaration
| 4
Lecture# 27 - 3D Array
 Two methods of initialization with declaration:
1. With internal braces { }
int Array[2][3][3] = {
{{1,1,1},{2,2,2},{3,3,3}},
{{4,5,6},{7,8,9},{10,11,12}}
}
2. Without internal braces { }
int Array[2][3][3] = {1,1,1,2,2,2,3,3,3,
4,5,6,7,8,9,10,11,12}
3D Array – Initialization
| 5
Lecture# 27 - 3D Array
3D Array – Printing
| 6
Lecture# 27 - 3D Array
3D Array – Printing with index
| 7
Lecture# 27 - 3D Array
3D Array – Accessing an element
| 8
Lecture# 27 - 3D Array
3D Array – Input elements
| 9
Lecture# 27 - 3D Array

Week 10 - Lecture 27 - 3D Arrays.pptx

  • 1.
    Week# 10 Multidimensional Arrays DrTaimur Ahmed Department of IT & CS, PAF-IAST
  • 2.
  • 3.
     A 3Darray is a multidimensional array used to store 3-dimensional data  In other words, a 3D array is an array of arrays  To visualize a 3D array, consider two 2D arrays when they are combined, they form a 3D array 3D Array | 3 Lecture# 27 - 3D Array a[0][0] a[0][1] a[0][2] a[0][3] a[1][0] a[1][1] a[1][2] a[1][3] Row 0 Column 0 Column 1 Column 2 Column 3 2x4 Row 1 b[0][0] b[0][1] b[0][2] b[0][3] b[1][0] b[1][1] b[1][2] b[1][3] Row 0 Column 0 Column 1 Column 2 Column 3 Row 1 2x4
  • 4.
     Use threedeclarators in definition: Data_type Name_of_Array[Array_Number][ROW][COLUMN];  First declarator is number of arrays; second is number of rows; third is number of columns const int ARR = 2, ROWS = 4, COLS = 3; int exams[ARR][ROWS][COLS]; 3D Array – Declaration | 4 Lecture# 27 - 3D Array
  • 5.
     Two methodsof initialization with declaration: 1. With internal braces { } int Array[2][3][3] = { {{1,1,1},{2,2,2},{3,3,3}}, {{4,5,6},{7,8,9},{10,11,12}} } 2. Without internal braces { } int Array[2][3][3] = {1,1,1,2,2,2,3,3,3, 4,5,6,7,8,9,10,11,12} 3D Array – Initialization | 5 Lecture# 27 - 3D Array
  • 6.
    3D Array –Printing | 6 Lecture# 27 - 3D Array
  • 7.
    3D Array –Printing with index | 7 Lecture# 27 - 3D Array
  • 8.
    3D Array –Accessing an element | 8 Lecture# 27 - 3D Array
  • 9.
    3D Array –Input elements | 9 Lecture# 27 - 3D Array