4.1 Arrays and Indexes
An array stores values of the same type. C array indexes start at 0.
c
int scores[5] = {88, 91, 76, 95, 83};
printf("%d\n", scores[0]);
printf("%d\n", scores[4]);An array of length 5 has valid indexes from 0 through 4. C does not automatically protect against out-of-bounds access, so scores[5] is dangerous.
Arrays are often processed with loops:
c
for (int i = 0; i < 5; i++) {
printf("%d\n", scores[i]);
}Loading interactive lab...
Loading concept check...
Loading practice...