Example 1: 3 dimensional array
int a[2][3]= {
{1, 2, 3},
{4, 5, 6}
};
cout << a[1][1];
int a[2][3][2]= {
{ {1, 2},
{2, 3},
{4, 5}
},
{ {6, 7},
{8, 9},
{10, 11}
}
};
cout << a[0][1][1];
Example 2: c fill 2d array
int disp[2][4] = {
{10, 11, 12, 13},
{14, 15, 16, 17}
};
int disp[2][4] = { 10, 11, 12, 13, 14, 15, 16, 17};
int i, j;
for (i = 0; i < HEIGHT; i++) {
for (j = 0; j < WIDTH; j++) {
disp[i][j] = disp[i][j];
}
}
Example 3: 2d array java
int[][]arr= new int [filas][columnas];
arr.length=filas;
int[][] a = {
{1, 2, 3},
{4, 5, 6, 9},
{7},
};
System.out.println("Length of row 1: " + a[0].length);
System.out.println("Length of row 2: " + a[1].length);
System.out.println("Length of row 3: " + a[2].length);
}
Example 4: c program to represent 2d matrix in 1d matrix
#include<stdio.h>
#define n 3
int main()
{
int a[n][n],b[n*n],c[n*n],i,j,k=0,l=0;
printf(“\n Enter elements of 2D array : “);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“\n Given 2D array : \n“);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(“%d ”,a[i][j]);
}
printf(“\n”);
}
printf(“\n Row wise \n”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[k]=a[i][j];
k++;
}
}
printf(“\n Column wise \n”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[l]=a[j][i];
l++;
}
}
}
Example 5: four dimensional array
I would explain how a 4 dimensional array works, but it's hard to explain it
in a 3 dimensional world, on a 2 dimensional screen,
for your 1 dimensional brain.