Array
Array (Definition):
An array is a fixed-size sequential collection of elements of the same data types grouped under a single variable name.
Declaring a one-dimensional array:
Syntax:
data-type variable-name [size];
Example:
int mark[5];
float avg[5];
By default array index starts with 0.
If we declare an array of size 5 then its index ranges from 0 to 4.
The first element will be stored at mark[0] and the last element will be stored at mark[4] not mark[5].
Like integer and float array we can declare an array of type char.
Initializing and accessing the array:
int mark[5] = {10,20,30,40,50};
printf("%d",mark[0]);
printf("%d",mark[1]);
printf("%d",mark[2]);
printf("%d",mark[3]);
printf("%d",mark[4]);
Drafted on 🌏 by,
Jal
☮
peace
Comments
Post a Comment