Three dimensional arrays in C/C++
Three dimensional arrays are the arrays which form n groups of n rows and n columns. Syntax as :
int arr[no of groups][of number of rows][of number of columns]
Example
#include<stdio.h> int main() { //this is defined as : // arr[no of groups][of three rows ][of four columns] // this will be read as : // two groups of three rows and four columns int arr[2][3][4] = { { // first 3x4 group { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 10 } }, // first group closed { // second 3x4 group { 11, 12, 13, 14 }, { 15, 16, 17, 18 }, { 19, 20, 21, 22 } } // second group closed }; // printing 3rd row and 3rd column of second group printf("%d",arr[1][2][2]); getchar(); return 0; }
Output
21