The Various types of Array are given below:-
(1) One Dimensional Array
(2) Two Dimensional Array
(3) Three Dimensional array
(4) Character Array of String
(1) One Dimensional Array
The one dimensional array or single dimensional array is the simplest type of array that contains only one row for storing data.
array_name[size];
int a[];
#include void main() { int i,a[5]={20,30,40,50,60}; for(i=0;i<5;i++) { cout<<"No Is " << [i]; } }
output:
No Is 20
No Is 30
No Is 40
No Is 50
No Is 60
(2) Two Dimensional Array
The Two Dimensional array is used for representing the elements of the array in the form of the rows and columns and these are used for representing the matrix.A Two Dimensional Array uses the two subscripts for declaring the elements of the Array
array_name[size1][size2];
int a[][];
#include void main() { int i,j,a[2][3]; for(i=0;i<2;i++) { for(j=0;j<3;j++) { cout<<"Enter value for a[%d][%d]:" << i << j; cin>>a[i][j]; } } cout<<"Two Dimensional array elements:"; for(i=0;i<2;i++) { for(j=0;j<3;j++) { cout<< a[i][j]; if(j==2) { cout<<"\n"; } } } }
output:Two Dimensional array elements:
1 2 3
4 5 6
(3) Three Dimensional array or Multidimensional array
A Three dimensional Array is used when we wants to make the two or more tables of the Matrix Elements for Declaring the Array Elements.
array_name[size1][size2][size3];
int a[][][];
#include void main() { int i, j, k; int a[3][3][3]= { {{1,1,1},{1,1,1},{1,1,1}}, {{2,2,2},{2,2,2},{2,2,2}}, {{3,3,3},{3,3,3},{3,3,3}} }; cout<<"Array Elements\n\n"; for(i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { cout<< a[i][j][k]; } cout<<"\n"; } cout<<"\n"; } }
output:Two Dimensional array elements:
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
3 3 3
3 3 3
3 3 3