# Array Declaration

 Tweet

What is an array?

An array is a sequenced collection of elements of the same data type. All the elements in an array have same size and data type. It is used to store large volume of similar data. For example:-

• Salaries of employees in an organisation.
• Marks of students obtained in an examination

A single dimensional array (more on this later) is simply declared like shown below:-

`int salary; `

where 'salary' is an array of integer data type which contains 15 elements.

SYNTAX

data type array_name[index];

"index" represents the total numbof elements in the array.

Types of Arrays:-

•  One Dimensional Arrays
• Two Dimensional Arrays
• Multi Dimensonal Arrays

ONE DIMENSIONAL ARRAYS

In a One Dimensional array we have a single index i.e. the array consists of only a single subscript.

Example:-

a,a,a,a,...........a[n-1]

It can be observed that total number of elements in above array is 'n'.

• In C Programming language, an array is initialised from zeroth element to (n-1)th element.
• But total number of elements will be 'n'.

An array can be declared in the following ways:-

• int num[]={2,8,7,6,0}; Here we dont need to mention the size of the integer array since we are assigning the values to all the elements at the time of the declaration itself.

• char a;
• a='A';
• a='B';
• a='C';

Here we have declared an array of character type by mentioning its size only at declration time and we have assigned the values later on.

Complete Source Code

```#include <stdio.h>
#include <conio.h>```
`void main()`
`{`
``` int a;
clrscr();```
``` a=120;
a=32;```
``` a=64;
a=9;```
``` a=170;
printf("Value of 1st element, a is %d \n",a);```
``` printf("Value of 2nd element, a is %d \n",a);
printf("Value of 3rd element, a is %d \n",a);```
``` printf("Value of 4th element, a is %d \n",a);
printf("Value of 5th element, a is %d \n",a);```
``` getch();

}```

Output of the program is shown below: Tweet
Tags: