![]() |
VOOZH | about |
Array is a data structure that is used to store variables that are of similar data types at contiguous locations. The main advantage of the array is random access and cache friendliness. There are mainly three types of the array:
Two Dimensional Array:
Difference Table:
| Basis | One Dimension Array | Two Dimension Array |
| Definition | Store a single list of the element of a similar data type. | Store a 'list of lists' of the element of a similar data type. |
| Representation | Represent multiple data items as a list. | Represent multiple data items as a table consisting of rows and columns. |
| Declaration | The declaration varies for different programming language:
| The declaration varies for different programming language:
|
| Dimension | One | Two |
| Size(bytes) | size of(datatype of the variable of the array) * size of the array | size of(datatype of the variable of the array)* the number of rows* the number of columns. |
| Address calculation. | Address of a[index] is equal to (base Address+ Size of each element of array * index). | Address of a[i][j] can be calculated in two ways row-major and column-major
|
| Example | int arr[5]; //an array with one row and five columns will be created. {a , b , c , d , e} | int arr[2][5]; //an array with two rows and five columns will be created. a b c d e f g h i j |
: