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 Parameter | Significance |
---|---|
data_type | Data Type of Each Element of the array |
Array_name | Valid variable name |
size | Dimensions of the Array |
Array declaration requirement
Requirement | Explanation |
---|---|
Data Type | Data Type specifies the type of the array. We can compute the size required for storing the single cell of array. |
Valid Identifier | Valid identifier is any valid variable or name given to the array. Using this identifier name array can be accessed. |
Size of Array | It is maximum size that array can have. |
What does C Array Declaration tells to Compiler ?
- Type of the Array
- Name of the Array
- Number of Dimension
- 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 –
Example | Type | Array Name | Dimension No. | No.of Elements in Each Dimension |
---|---|---|---|---|
1 | integer | roll | 1 | 10 |
2 | character | name | 2 | 80 and 20 |
3 | character | name | 3 | 80 and 20 and 40 |
No comments:
Write Comments