Skip to content

Latest commit

 

History

History
 
 

Array

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Array

An array is a list of elements of the same type, identified by a pair of square brackets [ ]. It is a collection of items stored at contiguous memory locations. To use an array, you need to declare the array with 3 things: a name, a type and a dimension (or size, or length).

The syntax is:

type arrayName[arraylength]

Array in Memory

Advantages

  • Random access of elements using array index.

  • Use of less line of code as it creates a single array of multiple elements.

  • Easy access to all the elements.

Disadvantages

To create an array, you need to known the length (or size) of the array in advance, and allocate accordingly. Once an array is created, its length is fixed and cannot be changed. At times, it is hard to ascertain the length of an array. Nonetheless, you need to estimate the length and allocate an upper bound. This is probably the major drawback of using an array.

Questions :