Monday, 10 May 2021

One dimensional arrays in C with examples

A one dimensional array is a group of elements of same type and stored under one subject or index. (OR)

A one dimensional array is single subscript variable which hold more one value under a single name.

i) Declaration of array

Like variables, arrays must be declared before storing values into it. The following is the syntax to declare a one dimensional array.

Syntax: type array-name[size];

Example: int a[3];

A declaration tells to the compiler three things 

1. Array type

2. Array name

3. Number of elements stored in the array( size of array)

ii) storing values on array or initialization

We can store values in array on the same way as the ordinary variable when they are declared. The general syntax is

Syntax: type array-name[size]={ list of values}

Example: int a[3]={10,20,30};

We can also store values incompletely like

Example: char ch[5]={'a','b','c'};

The rest of the locations stores default values depending on array types.

We can also store values individually using subscript like


We can copy an entire array into another array like

int b[3];


We can store values into large arrays using for loop like

int a[500];



scanf("%d", &a[i]);


 iii) Accessing elements of the array

The individual elements of an array are identified using the combination of array name and index value. We use the following general syntax to access individual elements of an array.

syntax: array-name[index value];




printf("%d", a[i]);



Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

Computer Basics


C Programming


Java Tutorial


Data Structures


MS Office


Database Management