## One Dimensional Array

What is Array?

Array is a collection of variables of same data type. Array is used to store more then one values of same data type under common name. All the variables in an array share one common name.
Number of values that can be stored in an array is fixed.
Array is also known as sequential list because in array all elements are arranged sequentially in memory.
Using array we can represent multiple values in the tabular form means in the form of row and column.

Types of Array

There are three types of array
(1) One Dimensional Array
(2) Two Dimensional Array
(3) Multi Dimensional Array

One Dimensional Array

One Dimensional Array can be represented using only one subscript.

Syntax
DataType ArrayName[Size];
Here,
Size indicates number of values that can be stored in an array.
Example
int a;
Here,
a is an array that can store 5 values of type integer.

Individual element of an array can be identify using an array name along with index. Index in an array always starts with 0. So First element is a, second is a and so on.

 a a a a a

Ammount of memory occupied by an array can be calculated using equation:
TotalMemory = ArraySize * Bytes Occupied By Data Type
Example:
float a;
= 10 * 4 (float Occupies 4 Bytes) = 40 Bytes
int a;
= 10 * 2 (integer Occupies 2 Bytes) = 20 Bytes
Bydefault all the elements of an array are initialized to 0.
It is also possible to initialize all the elements of an array at the time of declaring array(Compile Time).

Syntax
DataType ArrayName[Size]= {value1,value2,...valueN};
Example
int a={1,2,3};

If number of values specified in curly bracket is less then the number of elements in an array then remaining elements are initialized with 0.
If number of values specified in curly bracket is greater then the number of elements in an array then compiler will generate error.
It is also possible to initialize an array at run time.

Example
int i,a;
for(i=0;i<10;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
}