Arrays are the data structure having the linear relationship between the elements represented by means of sequential memory locations. Arrays contained the similar kind of elements (values or variables). Arrays are useful when the number of elements to be stored is fixed. Operations like traversal, searching and sorting can easily be performed on arrays.
Element- The values or data stored in an array is known as the elements of an array.
Index- For recognizing an element in the array each value is associated with a numerical key value known as Index of the element in the array. Index value in the array is starts with 0 for the first element.
An array can be represented just as any other variable in C, i.e. data followed by array name. The only modification in the declaration is the subscript in the bracket which indicates the number of elements it will hold. By declaring an array, the specified number of memory locations (size of array) are allocated in the memory.
int no_animals; float commissions; char colors;
The first example is of an integer type array where each element will hold an integer value, second one is the floating type array and the third is the character type array.
The elements of an array can be easily processed as they are stored in contiguous memory locations.
This is stored as
my_array my_array my_array my_array my_array
Basic Operations: Following are some operations performed on array.
Traversal: It involves processing each element in the list.
Searching: Searching or finding any element with a given value or the record with a given key.
Insertion: Adding a new element to the array.
Deletion: Removing an element from the array.
Sorting: Arranging the elements in some order.
Merging: Combining two lists into a single list.
Updating: Updating an element at the defined index.
Arrays can be initialized at the time of declaration. For Example
int age = [12, 45, 54, 21, 36]; float salary = [25000, 35000, 45000];