C - Language Theory
Arrays
An array is a collection(or blend) of elements. And it is used to store the multiple values in one variable. The value of an array is called an element of the array. An array can be of any type, for example int, char, float ..etc.
Array Declaration
Declaration of Array
An array is a collection(or blend) of elements. And it is used to store the multiple values in one variable. The value of an array is called an element of the array. An array can be of any type, for example int, char, float ..etc.
Syntax |
---|
int : Declare Data Type a : Array Name [5] : Array Size |
One Dimensional Array
One Dimensional Array
Size of array defines the number of elements in an array. Each element of array can be accessed and used by user according to the need of program.
Syntax |
---|
int : Declare Data Type a : Array Name [5] : Array Size |
Initialization One Dimensional Array
Initialization One Dimensional Array
Arrays can be initialized at declaration time in this source code as
Syntax |
---|
int age[5] = {2,4,6,8,9} |
Note: In do while loop the body will execute at least once irrespective of test condition.
Multi Dimensional Array
Multi Dimensional Array
The simplest form of multi dimensional array is a 2-dimensional array. It is also known as matrix. To declare multi dimensional integer array of size [x][y]. which means x is number of rows, y is number of columns can be shown in fig.
Syntax |
---|
int c[2][3] = {{2,4},{6,8,9}}
|