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

/*  Example Program For Single Dimensional Array In C++ Programming Language
    Array Example In C++*/

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

using namespace std;

int main()
{
   int i;
   
   // declaring and Initialising array in C
   int value[6] = {5,10,15,20,25,30};
 
	cout<<"Single Dimensional Array In C++ Example Program\n";
 
   for (i=0;i<6;i++)
   {
      // Accessing each variable using for loop
      cout<<"Position : "<<i<<" , Value : "<< value[i]<<" \n";
   }
   
   // 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