Array by definition is a variable that hold multiple elements which has the same data type.
In case of a simple variable there is a very big problem that a single value can be represented at a time by a single identifier. Hence if we want to represent multiple values through a single identifier than it is not possible through using single identifier. For this purpose c has provided yet another tool and it is called an array.
An array is a collection of multiple data items which are represented by the same identifier. The very main foundation is that all the values should be of same data types. In the technical terms the array is also called a script. The various locations where the values can be stored are called indexes and in the technical terms they are referred as subscripts. The various values stored on the indexes are called the elements or the contents.
The arrays are generally in the form of continuous memory locations i.e. each memory location is having the address of its next memory location which is the part of that array. Hence arrays are generally shown either in the form of rows or in the form of columns structure arrays are basically classified into two main categories and these are :
An array which is having either a single row or single column is termed as a one-dimensional array. One dimensional array have the subscripts in a linear manner.
two-dimensional arrayOne-dimensional array can store a list of linear variables but for storing the values which are in a tabular form, the multidimensional array are used. The multidimensional arrays can be though of having multiple rows and columns. In fact, when the wach index of one dimensional array is itself in the form of an array the upcoming structure is called a multidimensional array. Multidimensional arrays give the illusion of a matrix, since it is in the form of rows and column.
The arrays in the C can be implemented by writing the data types of the elements along with the array name and its index numbers (no. of locations).
Data type array name[size];
The array of characters is called string. The array elements can be called out by writing the array name and its index no. in the brackets.
Using arrays with loops
The most useful thing to do with an array is use it in a loop. This is because the element numbers follow a sequence just like a loop does.
When an array is declared the values are not set to 0 automatically. You will sometimes want to set the values of all elements to 0. This is called initializing the array. Here is an example of how to initialize an array of 10 elements using a for loop:
for (i = 0;i < 10;i++)
a[i] = 0;
An array with more than one index value is called a multidimensional array.
The arrays we have been using so far are called 1-dimensional arrays because they only have what can be thought of a 1 column of elements. 2-dimensional arrays have rows and columns. Here is a picture which explains it better:
You do get 3-dimensional arrays and more but they are not used as often. Here is an example of how you declare a 2-dimensional array and how to use it. This example uses 2 loops because it has to go through both rows and columns.
for (i = 0;i < 3;i++)
for (j = 0;j < 3;j++)
a[i][j] = 0;