C Array Declaration

In this tutorial we will be learning the C Array Declaration. A programmer need to specify the type of the elements and the number of elements required by an array.

C Array Declaration

Array has to be declared before using it in C Program. Array is nothing but the collection of elements of similar data types.

Syntax

<data_type>  array_name  [size1][size2].....[sizen];
Syntax ParameterSignificance
data_typeData Type of Each Element of the array
Array_nameValid variable name
sizeDimensions of the Array

Array declaration requirement

RequirementExplanation
Data TypeData Type specifies the type of the array. We can compute the size required for storing the single cell of array.
Valid IdentifierValid identifier is any valid variable or name given to the array. Using this identifier name array can be accessed.
Size of ArrayIt is maximum size that array can have.

What does C Array Declaration tells to Compiler ?

  1. Type of the Array
  2. Name of the Array
  3. Number of Dimension
  4. Number of Elements in Each Dimension

Examples of C Array Declaration

Examples : Declaring 1D array

// Array of 10 integer roll numbers  
int roll[10]

In the above example we are declaring the integer array of size 10. Array is single dimensional and have

Examples : Declaring 2D array

// 2-D Array
char name[80][20];

In the above example we are declaring 2D array which has 2 dimensions. First dimension will refer the row and 2nd dimension will refer the column.

Examples : Declaring 3D array

// 3-D Array
char name[80][20][40];

Above declaration tells compiler following things –

ExampleTypeArray NameDimension No.No.of Elements in Each Dimension
1integerroll110
2charactername280 and 20
3charactername380 and 20 and 40