Professional Documents
Culture Documents
FSC1331/FDN1120
Topic 9 : Arrays
17/01/2016 1
9.1 Array Declaration
17/01/2016 2
9.1 Array Declaration
• Once an array is declared, individual slot could be used for
storage and these slots are referenced via index.
• The first slot starts at zero.
• Each slot in the array could be referred by specifying the array
name and the index.
• For example, the statement SalesArray[2] would refer to third
slot’s stored value
17/01/2016 3
9.2 The Variably Defined Array
• In some situations, it is important for us to access different
elements, essentially different variables, by changing the
index.
• The advantage of using variably defined variable in the array
index is, it would reduce/simplifies the array operations.
• Consider an array with hundred elements, and if the value of
each element were to be displayed/printed, individual access
would require the same /statement code to be repeated
hundred times in a program.
• This would not happen if the index were declared variably.
17/01/2016 4
9.2 The Variably Defined Array
17/01/2016 5
9.3 Sample Program
17/01/2016 6
9.3 Sample Program
17/01/2016 7
9.3 Sample Program
Error?
Correction?
17/01/2016 8
9.3 Sample Program
Idx+1
17/01/2016 9
9.3 Sample Program
17/01/2016 10
9.3 Sample Program
17/01/2016 11