C Arrays
C Arrays
In this tutorial, we will learn about C Arrays. An array is a collection of elements of the same data type stored in continuous memory locations.
Declare Array
The general syntax to declare an array is as follows:
<data type> <array name> [size];
For example, to declare an array to store six integer numbers:
int numbers[6];
The numbers array is of a single dimension or 1D array.
In this statement, we have declared the array and have not initialized the array elements.
Array Initialization
We can also initialize the fixed length array during the array declaration as shown below:
Example
int numbers[6] ={4,7,9,12,34,46};
An array is a data structure of multiple elements with the same data type. Array elements are accessed and stored using the array index.
The memory allocation of the array in the example would be as shown below:
In C language, the array index starts with 0. The first array element can be accessed using
numbers[0]
The valid range of the index is 0 to size – 1.