Array in C Programming

Array is a collections of similar data types. That's provide us to store large amount of data in single variable.

Array in C Programming
Array in C Programming

What is Array?

Array is a collections of similar data types. That's provide us to store large amount of data in single variable. It's also provide easy way to manage the data. And it's stored data in continuously way in the  memory.

History of Array

Array was introduce at the same time when c language launch.

Time to time array was improve like variables length arrays (VLAs) and enhance features just like memory managing and array is become more versatile.

Features of Array

  • Array is store large number of data in single veritable.
  • It's store data in Continuously memory location.
  • All elements in array are same data type. If we stored data in integer then all data are integers or character then all data are characters.
  • Array are defined in fix size. Just like "array[50]".
  • It is more effective and faster to execute the code.
  • In tha Array,  source code has fixed size and can't modify the run time.
  • In Array simply to find the location of specific elements.

Array declaration

Important: data_type array_name[size] = {list of the value};

Example:-

// Array store 5 elements

#include<stdio.h>

Int main(){

Int array[5] = {2,4,6,8,10};

printf("%d",array[5] ); 

return 0;

}

Types of Array 

One Dimension Array: 

It contains data in single row.

Example:-

data type array name[size] = {list of the value};  

    Int array[9] = {0,2,4,6,8,9,10,12,14};

    Int array[5] = { 'H' , 'E' , 'L' , 'L' , 'O' };

Two Dimension Array:

It contains date in row and column.

Example:-

data type array name[row size][column size] = {list of the value}; 

    Int array[3][3] = { {4,5,6} , {1,2,3} , {7,8,9} };

Multi Dimensions Array:

It contains higher dimension like , 3D array.

Example:-

data type array name[size1][size2][size3]......[size N] = {list of the value}; 

    Int array[4][3][2];

Array Traversal 

We use loops for the elements in Array that called Array Traversal

Steps for Array Traversal

  • Declare an Array
  • Use a Loop 
  • Access Elements
  • Perform Operations

Example:- 

#include<stdio.h>

int main(){

int i,array[5]

    for(i=0;i<5;i++){

    printf("%d",i);

    };

return 0;

}

More about Array

  • Dynamic Array: If the Array declared using memory Allocation technique, it is called Dynamic Array.
  • Dynamic Memory Allocation: It is process of allocating memory at run time, it is called Dynamic memory technique.
  • Static Array: when the Array declared using static memory Allocation technique, it called static Array.
  • Static memory Allocation: It is process of allocating memory at compile time, it is called static memory Allocation.

Post a Comment