Advantages and disadvantages of Arrays
Overview
Let’s look at some of the advantages and disadvantages of using Arrays in this tutorial. An array is a data structure that stores a collection of elements of the same data type. The array elements are stored in successive memory locations.
Advantages of arrays
Some of the advantages of using arrays are as follows:
- Arrays allocate memory in contiguous memory locations for the elements. Array elements can be accessed randomly by using the array index number.
- Arrays represent multiple data items of the same type using a single name. There is no need to declare several variables to store the elements. We can use the single array name to store and retrieve the array elements.
- Two-dimensional arrays are used to represent matrices.
Disadvantages of arrays
Some of the disadvantages of using arrays are as follows:
- The programmer should know the maximum number of elements that the array can hold. The number of elements to be stored in an array should be known in advance.
- An Array is not dynamic. It is a static structure which means the array is of fixed size once declared the size of the array cannot be modified.