Array
is a sequence of data items that are of the same type, indexable by the use of subscripts, and stored contiguously
why?homogeneous data
- eg. 7 students grades:
- int grade0,grade1,grade2,grade3,grade4,grade5,grade6;
- 10 characters: char c0,c1,c2,c3,c4,c5,c6,c7,c8,c9; etc.
it is cumbersome to represent and manipulate the data by means of unique identifiers.
int grade[7]; declare an array of size 7, individual elements of the array are accessed using a subscript where indexing of array elements always starts at 0 i.e. grade[0], grade[1], grade[2], grade[3], grade[4], grade[5],grade[6]
as with variables, arrays can be initialized within a declaration using array initializer.
eg. float x[5] = {1.1,0.2,33.0,4.4,5.05};