Introduction to Arrays


An array is a collection of similar types of data items and each data item is called an element of the array. The data type of element may be float, int, char, float, etc. All the elements of the array share the same variable name. But each element has a different index known as a subscript. It is one of the most common data structures used.

Arrays can be single-dimensional or multidimensional. Two-dimensional arrays are known as matrices. So the number of subscripts defined will determine the dimensions of the array.

reperesentataion of array

A simple program to explain the use of the array can be to find the average marks obtained by a class of 30 students in the test. So in this, if you can solve the problem by declaring 30 variables or by creating an array of 30 students. Which is much simpler than creating 30 variables. below is the c code for the program

int main(){
int avg,sum=0;
int i;
int marks[30];//array declaration
for( i=0;i<30;i++){
printf("enter the marks");
printf("average marks is =%d\n",avg);
return 0;

Array declaration

Is done in square brackets like int marks[30]. Here int is the data type and [30] tells the compiler how many elements of type int will be in the array. this is also called the ‘dimension’ of the array.

Accessing elements of array

Once an array is declared an individual element in it is referred to using marks[0], marks[1], marks[2], etc. The numbers used [] in specifies the position of an element in the array. Array elements are counted starting from 0,1,2. so marks[2] is the third element not the second.

Array Intialization

int num[6]={1,2,3,4,5,6};
int n[]={233,67a};
float gdp[2]={1.1,1.5};

This shows arrays can be initialized while declaring them.

The speed of an array data structure makes it perfectly suited for ‬more complex data types, such as hash tables.‭ ‬The predictability of the memory addresses of the elements also can be used to implement very fast array algorithms that can move data quickly.‭ ‬This is particularly useful for sorting operations such as bubble sorts‭ ‬that are perfectly suited for use with arrays.

We will be happy to hear your thoughts

Leave a reply

Open chat
Scan the code
Can we help you?