Array Types In C++
There
are three type of array in c language and they are:
1.One
dimensional array
2.two
dimensional array
3.multi-dimensional
array
1 .
One dimensional array
One dimensional array is type of array it use subscript and the size of array is declare in subscript of array.
Syntax:
datatype
arrayname[size];
Example:
int a[5];
Program
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[5]={10,20,30,40,50};
for(int i=0;i<=5;i=+)
{
Cout<<“value of arr[%d] is %d \n”,i , arr[i];
}
getch();
}
Output:
value of arr[0] is 10;
value of arr[1] is 20;
value of arr[2] is 30;
value of arr[3] is 40;
value of arr[4] is 50;
2. Two dimensional array
Its use two subscript first row and second column and array use for creating matrix in which data is store on memory in table format.
Syntax:
datatype
arrayname[row][column];
Example:
int arr[2][2];
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
int
arr[3][3], i,j;
cout<<“count 3* 3 Matrix”;
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
cin>>“%d%d”,&arr[i][j];
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
cout<<“%d%d”,arr[i][j];
cout<<“\n”;
getch();
}
Output:
Count 3*3 matrix
2
2
2
2
2
2
2
2
2
222222222
3. Multi-deminsional array
In this array we use two are more than two subscript
of array.
Syntax:
datatype arrayname[size][size][size] ;
Example:
int arr[2][2][2];
No comments:
Post a Comment