The following for loop initializes all the values in the above array: a to zero:

for (i = 0; i < 10; i++) a[i] = 0;

Notice that i goes from 0 to 9. It is very important that you stay within the 'bounds' of the array. Compilers don't usually catch errors like: a[10] = 0; and they can have very destructive results.

 


Questions from Students

  1. King's book says that in array subscripting we always start filling in from a[0]. if you start filling in the array from a[1] instead of the conventional a[0], does it mean that C will automatically store the first data you read in the second field and leave a[0] as zero or somehow since it is the first data read, it will still be stored in the first position i.e. a[0].
     

main page