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 Parameter Significance
data_type Data Type of Each Element of the array
Array_name Valid variable name
size Dimensions of the Array

Array Declaration Requires -

  1. Data Type

Data Type specifies the type of the array. We can compute the size required for storing the single cell of array.

  1. Valid Identifier

Valid identifier is any valid variable or name given to the array. Using this identifier name array can be accessed.

  1. Size of Array

It 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 –

Example Type Array Name Dimension No. No.of Elements in Each Dimension
Example 1 integer roll 1 10
Example 2 character name 2 80 and 20
Example 3 character name 3 80 and 20 and 40