
8.4 Basic Computer Engineering
8.3 ACCESSING VALUES OF AN ARRAY
As discussed earlier, the array elements can be individually referenced by Array_name and index.
Thus, elements are accessed through loop to read or modify values. Program 8.1 illustrates the process of
initializing and accessing an array.
The syntax is Array_name[index]
So, for example, to set the third element as 66, we may write:
marks[2] = 66 ;
To assign value of the third element of marks to a variable called p, we could write:
int p = marks [ 2 ] ;
Attempting to access a non-existent array element (e.g. marks[ 5 ] in Program 8.1) does not cause
compilation errors but leads to ...