One dimensional array in c

in One dimensional array the data elements are stored in linear manner. the elements have the same name and same data type but different index number. for example we can assume the one-dimensional arrays as single column matrix or single row matrix


Data_type array_name [size];


int x[30]
float x[50]
char name[100]

so, let’s look into the above examples. first int [30] can store 30 elements but the data type is int ,so it can store only integers .we can refer specific elements by using data type and name of the array and the specified index number. the first element in every array is a zeroth element, that is the index number of 1st element is 0,so if nth element of an array has index number [n-1]

Static array initialization

one dimensional arrays are linear ,we can consider single row matrix. array elements can be initialized in form of flower brackets and each element is separated by comma (,) and ended with semi colon(;)

int x[5]={2,7,1,8,3};

it is not necessary to define the size of array during initialization

int x[ ]={2,7,1,8,3};

in this case compiler automatically determines the size of an array by comparing with number of elements in that array

Insertion sort

Dynamic array initialization

Dynamic array initialization is useful programs because ,in this user give the values to the array elements and these can be deleted or editable in further program. to assign values from the user the program must be written with loop condition using the arrays index numbers to make program sortable.


#include <stdio.h>
int main()
int marks[10],i,n,sum=0;
printf("Enter number of students: ");
printf("Enter marks of student%d: ",i+1);


Enter number of students: 3
Enter marks of student1: 90
Enter marks of student2: 56
Enter marks of student3: 47