C Language



Admission Enquiry Form

  

Array in C

What is Array in C ?

Array is a technique which is used to store more than one value but of similar type.It stores the values in contigeous or adjacent memory location.Every element of an array having its unique index number.

Instead of declaring individual variables, such as number0, number1, ..., and number99, we can declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index.




Syntax to declare an array

data_type  arrayName[arraysize];

This is called a single-dimensional array. The arraySize must be an integer constant greater than zero and type can be any valid C data type. For example, to declare a 5-element array called num of type int, use this statement:

int num[5];

Now num is available array which is sufficient to hold upto 5 integer numbers.




Initializing Arrays

int num[5] = {10,20,30,40,50};

The number of values between braces { } can not be larger than the number of elements that we declare for the array between square brackets[].

If you omit the size of the array, an array just big enough to hold the initialization is created. Therefore, if you write:

int num[] = {10,20,30,40,50};





Types of An Array