Loading, please wait...

Single Dimensional Array

The single dimensional array is used to store data in sequential order. The single dimensional array contains only one subscript/index in their declaration, like int myarray[500];

In the one-dimensional array, we can access any element using one index reference, like myarray[15].

 

Example:

/* How to use a single Dimensional array in C */
      #include<stdio.h>
int main()
{
int i;
/* Initialize the value of array */
int myarray[5] = {51, 52,  53, 54, 55};

for(i=0; i<5;i++)
{
/*Accessing the elements of myarray*/
printf(“Element of myarray[%d] is %d \n”, i, myarray[i]);
}}

 

Output:

 Element of myarray[0] is 51

 Element of myarray[1] is 52

 Element of myarray[2] is 53

 Element of myarray[3] is 54

 Element of myarray[4] is 55