Cambridge igcse computer science book

Page 244

Activity 12.1 Using the high-level programming language that your school has chosen, find out about arrays. a Is the first element 1 or 0? b How do you declare the size of an array? c Can you declare the type of the array? d Declare an array to store the test marks for a class of 30 students.

12.2.2 Using a variable as an index in an array In order to repeat the same task many times for all the items in a list, each item needs to be referred to in the same way using the index number for each element of the onedimensional array. If a variable is used for this index number, then the same code can be re-used for each item.

Figure 12.4 Using a variable as an index in an array This allows several arrays to be used together with the same index number to show related information, for example, each student could sit more than one test and the name and gender of the student could also be recorded.

244


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.