C Arrays

An array is a series of elements of the similar type placed in contiguous memory locations that can be accessed individually by adding an index or subscript to a unique identifier. An array is made up of a key and a value pair, and the key points to the value. Arrays may be of any variable type.

Types of an Array

  • One / Single Dimensional Array
  • Multi dimensional array ( Example : Two dimensional array )

Single / One Dimensional Array :

A one-dimensional array is a structured collection of array elements that can be accessed individually by specifying the position of a element with a single index value.

Declaring Single Dimensional Array

Example:

Initializing an Array

Accessing Array’s Elements

An array elements can be accessed easily by index or subscript like array_name[index]. Indexing for an array starts from zero (0) to the last element of an array is array_name[size-1] where size is the number of elements of the array.

Example program for one/single dimension C array:

Output:

Multi dimensional array ( Example : Two dimensional array )

Multidimensional arrays is nothing just an array of arrays. We can declare a multidimensional array, as below:

Example program for two/multi dimension C array:

Output: