Array in C Programming

Array is a kind of data structure that can store a elements of the same type. Arrays stores the elements in a contiguous memory locations.

Array is a collection of similar type elements

 For example: we want to declare 100 integer variable

Instead of declaring 100 individual variables, such as

int number0, number1,number2,number3, … …., number99;

you declare one integer array variable such as

int number[100];

here number[100] is an integer array of size 100, means this array can store 100 integer value.

Array indexing starts from index 0 to n-1. Means first integer number store in array number[0], second integer number store in array number[1], third integer number store in array number[2], and so on. Here 100th  number store in array numbers[99].

Declaring Array

Syntax of declare an array in C:

DataType  arrayName [ arraySize ];

This is called a single-dimensional array.

The arraySize is an integer constant greater than zero.

datatype can be any valid C data type.

Example: write a program to create integer array and store 5 integer number and print.  

Example: write a program to take 5 number from user and store integer number in integer array and print.  

Another way to Initialize Array

We can also initialize array by this way:

int num[5] = { 54 , 4,  13,  2,  17 };

above integer array num[5], stores five numbers. Where num[0] store 54, num[1] store 4….. , & num[4] store 17.