Array In C Language
C
array is a collection of variable
belonging to the same data type. you may store group of data same data type in
array.
Array
might be belonging to array of the data types.
Array
size must be constant value.
Array
starting form 0 size.
Always,
Contiguous (adjacent) memory location are used to store array elements in
memory.
It
is a best practice to initialize an array to zero or null while declaring, if
we don’t assign any value of array.
Fig: Array in c |
Example:
int a[10];
How to declare an array?
datatype arrayname[size];
Example:
float mark[5];
Access array element
We
caqn access elelment of an array by indices.
We
declare an array is mark,then first element is mark[0],and second is mark[1]
and so on.
Fig:Declaration in c |
How to initialize an array?
It
is possible to initialize an array during declaration
Example:
int mark[5]={10,11,12,13,14};
Now
we can initialize like this also
int mark[ ]={10,11,12,13,14};
Here
we specified the size so compiler know its size is 5 as we are initializing it with 5 elements.
Fig: Initialize array in c |
No comments:
Post a Comment