An array is a collection of similar kind of data elements stored in adjacent memory locations and are referred to by a single array-name. The first element in the array is numbered 0, so the last element is 1 less than the size of the array. Before using an array its type and dimension must be declared.

  • Array is a data structure storing a group of elements, all of which are of the same data type.
  • all arrays in C are indexed from 0 up to one less than the bound given in the declaration.
  • All the elements of an array share the same name, and they are distinguished from one another with the help of an index.
  • Random access to every element using a numeric index.
  • The declaration of an array is just like any variable declaration with additional size part, indicating the number of elements of the array. Like other variables, arrays must be declared at the beginning of a function.

Array Declaration


  • The declaration specifies the base type of the array, its name, and its size or dimension. array is called a homogeneous data structure. The data type of an array applies uniformly to all the elements.
  • The amount of storage for a declared array has to be specified at compile time before execution. This means that an array has a fixed size.

Syntax of Array Declaration

data-type array_name [constant-size];

      Data-type refers to the type of elements you want to store

        Constant-size is the number of elements

Example of declarations for arrays:

[cc lang=”bash” escaped=”true” width=”auto” nowrap=”0″ theme=”blackboard” line_numbers=”off” ]

int marks [60];

float numbers [100];

static int roll_no [60];

char subject [30];


Initialization of Array Elements in the Declaration

The values are assigned to individual array elements enclosed within the braces and separated by comma. Syntax of array initialization is as follows:

data type array-name [ size ] = {val 1, val 2, …….val n};

val 1 is the value for the first array element, val 2 is the value for the second element, and val n is the value for the n array element. Note that when you are initializing the values at the time of declaration, then there is no need to specify the size. Let us see some of the examples given below:

[cc lang=”bash” escaped=”true” width=”auto” nowrap=”0″ theme=”blackboard” line_numbers=”off” ]

int digits [10] = {1,2,3,4,5,6,7,8,9,10};

int digits[ ] = {1,2,3,4,5,6,7,8,9,10};

int vector[5] = {12,-2,33,21,13};

float temperature[10] ={ 31.2, 22.3, 41.4, 33.2, 23.3, 32.3, 41.1, 10.8, 11.3, 42.3};

double width[ ] = { 17.33333456, -1.212121213, 222.191345 };

int height[ 10 ] = { 60, 70, 68, 72, 68 };


Multi-Dimensional Arrays

Arrays with more than one dimension are called multi- dimensional arrays. The first number in brackets is the number of rows, the second number in brackets is the number of columns. So, the upper left corner of any grid would be element [0][0]. The element to its right would be [0][1], and so on. Here is a little illustration to help.












Multi-Dimensional Array Declaration

You can declare an array of two dimensions as follows:

datatype array_name[size1][size2];

variable_type is the name of some type of variable, such as int. size1 and size2 are the sizes of the array’s first and second dimensions, respectively. Here is an example of defining an 8-by-8 array of integers

int chessboard [8][8];


Related Post

Strings String can be represented as a single-dimensional character type array. Strings in C are group of characters, digits, and symbols enclosed in quotatio...
Introduction to Java Programming Language JAVA TUTORIALS Introduction to Java Programming Language What is JAVA Java is programming language that produces software for multiple platforms, w...
Dart Libraries | Dart Tutorial Dart Libraries Dart has the following libraries, which are included in all Dart platforms: dart:core This library is automatically imported into ev...
Use of CollectionViewDataSource method moveItemAt ... Use of CollectionViewDataSource method moveItemAt for Reordering CollectionView cell In IOS (Swift 4) In this tutorial we are study about how we can r...
Variables Variables A variable is a named location in memory that is used to hold a value that can be modified by the program. All variable must be declared be...
Introduction To C A Brief History Of C   C was invented and first implemented by Dennis Ritchie on a DEC PDP-11 that used the Unix operating system. C is the r...

Write A Comment