C Array Basic

C Array Introduction :

In the previous chapter’s we have learn’t variables are used for the storage of the data. Variables are the one of the building block in C Programming.

So far we were using the single variable name for storing one data item. If we need to store the multiple copies of the same data then it is very difficult for the user.

Consider following example -

Suppose we have to store the roll numbers of the 100 students the we have to declare 100 variables named as roll1,roll2,roll3,…….roll100 which is very difficult job. Concept of array is introduced in C which gives the capability to store the 100 roll numbers in the contiguous memory which has 100 blocks , which can be accessed by single variable name.

  1. Array is the Collection of Elements
  2. Collection of the Elements of the same data type.
  3. All Elements are stored in the Contiguous memory

C Array : Pictorial Look

The above array is declared as int a[5];

a[0] = 4;
a[1] = 5;
a[2] = 33;
a[3] = 13;
a[4] = 1;

4,5,33,13,1 are actual data items … ( in our case Roll numbers )
0,1,2,3,4 are index variables ..( similar to ‘i’ in for loop / Subscript variable )


Definition of Array :

Array is collection of the data items having same data type

What is index or Subscript variable ?

  1. Individual data items can be accessed by the name of the array and an integer enclosed in square bracket called subscript variable / index
  2. Subscript Variables helps us to identify the item number to be accessed in the contiguous memory.