C Array Declaration

Array Declaration in C

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 Requires -

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 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 : 1

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

Examples : 2

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

Examples : 3

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

Above declaration tells compiler following things -

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