Types of Arrays

Types of Arrays

Published by: Nuru

Published date: 21 Jun 2021

Types of Arrays Photo

Types of Arrays

There are two types of arrays: Single dimensional Arrays and Multidimensional Arrays. We characterize these types of arrays on the basis of dimensions. Dimension here means index.

  • One Dimensional Array

One dimensional array is those arrays whose list of items can be given one variable name using only one subscript or dimension or index. The value of the single subscript or index from 0 to n-1 refers to the individual array elements. Here, n is the size of the array.

For a single-dimensional array, the size is specified by a positive integer expression which is enclosed in the square brackets. We write the expression usually as a positive integer constant. In general terms, we define a one- dimensional as:

Storage- class data- type array [expression];

Here, storage –class refers to the storage class of the array, data-type is the data type we use, the array is the array name and, the expression is the positive-valued integer which indicates the number of array elements. The storage-class is optional and, the default values are automatic for arrays. We define these within a function or a block and external for arrays outside a function.

Types of array

 

In the diagram above, x is an n-element, one-dimensional array.

  • Multi-Dimensional Array

Multidimensional Arrays are as same as single-dimensional arrays. The only thing different in it is that it needs a separate pair of square brackets for each of the subscript. A two-dimensional array will require two pairs of square brackets, a three-dimensional array will require three pairs of square brackets. The pair of square brackets increases as an increase in the number of dimensions.

In general terms, we define a multidimensional array as:

Storage- class data- type array [expression 1] [expression 2] [expression n];

Here storage class refers to the storage-class of arrays, the data-type is the data type we need, the array is the array name, and expression 1, expression 2, …., expression n are the positive-valued integers expression. These indicate the number of array elements related to each subscript. Here also, the storage class is optional.

 

Types of array