Single Dimensional Array Example Program in C Programming

Definition

An array is a collection of data that holds homogeneous values. That means values should be in same type

Syntax

type variable_name[size]

Details of Array

int varName[10];

Here, varName has 10 containers,

varName[0], varName[1] to varName[9]

For example,

Array values stores like below structure,

int value[6] = {5,10,15,20,25,30};

Value[0] = 5
Value[1] : 10
Value[2] : 15
Value[3] : 20
Value[4] : 25
Value[5] : 30

Example Program for Single Dimensional Array

/*  Example Program For Single Dimensional Array In C Programming Language
    little drops @ thiyagaraaj.com
    Coded By:THIYAGARAAJ MP             */

// Header Files
#include<stdio.h>
#include<conio.h>

int main()
{
   int i;
   
   // declaring and Initialising array in C
   int value[6] = {5,10,15,20,25,30};
 
   for (i=0;i<6;i++)
   {
      // Accessing each variable using for loop
      printf("Position : [%d] , Value : %d \n", i, value[i]);
   }
   
   // Wait For Output Screen
   getch();

   //Main Function return Statement
    return 0;
}

Sample Output:

Position : [0] , Value : 5 
Position : [1] , Value : 10 
Position : [2] , Value : 15 
Position : [3] , Value : 20 
Position : [4] , Value : 25 
Position : [5] , Value : 30