Introduction to Arrays in C

This “Introduction to Arrays in C” page explains clearly about what is the definition of array, syntax and memory allocation.


 

Array:

  • Array is a derived data type.
  • Array is a linear data structure.
  • Array store elements in consecutive memory locations.
  • Using primitive data type variables, we can store only one element at a time.   

       void main()
        {
            int a=10;
            a=20;
            a=30;
            printf(“a : %d\n”,a);
        }

 

  • Disadvantage of primitive variables is, we cannot process the information like storing phone numbers, account numbers, students marks…..
  • Using array variables, we can store more than element.
  • Arrays can hold only homogeneous data elements.

 

Syntax :
<data_type> <Identifier> [size];

Ex : 
int arr[5];

 

  • The above statement is an array declaration, in which “arr” is a variable which holds 5 elements of integer data type.
  • All the elements of array will gets consecutive memory locations.
  • Array variable holds base address ( first element address) of array.
  • Array elements can be accessed using it’s index number (starts with 0 to size-1).

 

Share this