Types of Arrays:
One-Dimensional Arrays:
An One-dimensional Array is an list of data with similar DataTypes referred by an common name.It can be Defined as:
Array_name[size of array] = {x,y....,z}
*note: The Array index always starts at 0
It is the simplest form of array in which data are stored in an linear fashion.
say,
int num[4] ={2,6,5,4}
then the elements in array are stored as:
data 2 6 5 4
index 0 1 2 3
Total memory occupied by an One-Diamensional array : (size of dataType) * size of array
Two-Dimensional Arrays:
Instead of being an list of data's, an Two-dimensional Array is an array of arrays with similar datatype referred by an common name.An Two-dimensional Array consists of List of lists rather than list of data's.It can be defined as:
Array_name[row][column]={x,y,.....z}
In Two dimensional Array, data are stored in matrix form.
say (let's take the same example as in One-Dimensional Array and implement it in 2-D Array),
int num[2][2]={2,6,5,4}
then the elements in array are stored as:
data 2 6 5 4
index 0,0 0,1 1,0 1,1
total memory occupied by an Two-Dimensional Array: (size of DataType) * size of 1st index * size of 2nd index
Multi-Dimensional Arrays:
Multi-Dimensional Arrays are arrays containing two or more than two levels. As the Two-Dimensional Array contained Two levels i.e. Rows and Columns, it is also an Multi-Dimensional Array.An multi-dimensional array may contain n levels,Array_name[a][b][c]....[n]={x,y.....z}
No comments:
Post a Comment