The number of variables used so far in a program is very limited. But in real life, plenty of elements are required to be dealt with. Like, we have already written programs to find out maximum between two, three or four variables, but if our task is to find the highest marks in a class of 60 students or more, then it will become a tedious job for us. Which means 60 variables are to be declared to store marks of 60 students, so 60 scanf statements have to be used to take input the marks of each student and finally 60 if statements to find the maximum of these marks and so on. Not only that, if another class contain less or more than 60 students, we could not use this program for that class. We have to rewrite the program according to that new class. Thus this approach of processing a large set of data is too cumbersome and surely not flexible enough. The C language (rather all modern high level languages) provides a more convenient way of processing such collections. The solution is Array or Subscripted variables.
WHAT IS AN ARRAY?
An array is a collection of homogeneous (i.e., same data type) data elements described by a single name and placed in contiguous memory locations. Each individual element of an array is referenced by a subscripted variable, formed by affixing to the array name a subscript or index enclosed in brackets.
Thus by declaring an array we can store a set of values, say 60 of type int in a single variable without declaring 60 different variables of different names. All these values will be stored under a unique identifier (array name).
Review the options below to login to check your access.
Log in with your Cambridge Aspire website account to check access.
If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.