An array in computer programming is a data structure that consists of a collection of elements or data items of the same type, stored in contiguous memory locations. It allows for the organization and manipulation of data in a systematic and linear way. There are 2 types of array.
Arrays are commonly used to store and access a fixed number of elements of the same data type, making it easier to work with related sets of data. Array stores similar datatype and provide random access to data elements via indexing.
Array Schema : Array Name | Array Datatype | Array Size
Array Operations : insertion, searching, display, traverse, deletion and update
There are two types of Array:
1. One-Dimensional Arrays
A one-dimensional array is a linear array with single subscripting. Brackets [] are used for the array subscript to declare and access its elements.
Eg: int a[11];
2. Multi-Dimensional Arrays
Arrays with more then one dimension is referred as 2 dimensional array, they can be 2 D , 3D and so on.
- Two-Dimensional Arrays:
Arrays with two subscripts [][] are known as two-dimensional arrays. They are tabular in nature; it has rows and columns.
Eg : int arr[6][6];
- Three-Dimensional Arrays:
Used to create complex Tables / Matrix of elements, it is declared with three subscripts.
Example: int a[9][9][6];
Note: One-dimensional arrays involve single subscripting, while two-dimensional arrays use two subscripts to handle tabular data.
Pros of Arrays:
- Storing data of the same size and type
- Represents multiple data items of the same type using a single variable.
- Easier visualization and Simpler Syntax.
- Data type standardization and random access of data elements.
Cons of Arrays:
- Insertion and deletion are complex and resource intensive due to sequential storage nature of an array and shifting has to be carried out in order to insert an delete elements .
- Static structure with fixed memory size and sequential memory allocation.
- Only Applicable to Specific Use cases
The article above is rendered by integrating outputs of 1 HUMAN AGENT & 3 AI AGENTS, an amalgamation of HGI and AI to serve technology education globally.