Arrays:
Arrays is a collection of data element of the same data type i.e. array can store more than one value in variable of same data type. To define an array write down the following syntax.
<storage class> <datatype> arrayname [index];
In above syntax, index is a non negative (positive) integer inclosed in [ ] placed immediately after the array name and index hold integer value starting with 0. thus for array [10] index will be from 0 to 9.
a[5] = a[0],a[1],a[2],a[3],a[4]
Here, zero is known as lower bound and four is known as upper bound.
If user tries to access an element outside the legal index range. It won't give any error. But it may access some junk value, which can lead to unpredictable result. There are two types of arrays :
1) One dimensional array.
2) Two dimensional array.
Array Initialisation in C :
Initialisation of an array can be done by using for loop or by dynamically allocating values for that array. To allocate values dynamically, you can write as follows:
int a[5] = {10,45,27,76,4};
Arrays is a collection of data element of the same data type i.e. array can store more than one value in variable of same data type. To define an array write down the following syntax.
<storage class> <datatype> arrayname [index];
In above syntax, index is a non negative (positive) integer inclosed in [ ] placed immediately after the array name and index hold integer value starting with 0. thus for array [10] index will be from 0 to 9.
a[5] = a[0],a[1],a[2],a[3],a[4]
Here, zero is known as lower bound and four is known as upper bound.
If user tries to access an element outside the legal index range. It won't give any error. But it may access some junk value, which can lead to unpredictable result. There are two types of arrays :
1) One dimensional array.
2) Two dimensional array.
Array Initialisation in C :
Initialisation of an array can be done by using for loop or by dynamically allocating values for that array. To allocate values dynamically, you can write as follows:
int a[5] = {10,45,27,76,4};
No comments:
Post a Comment