An array contains elements of one type in consecutive storage. Indexing starts at zero. sizeof the complete local array divided by sizeof one element gives its element count. size_t is an unsigned type used for sizes and indexes.
Read the example
The complete program appears below. Read it first, predict the output, then run it.
Expected output
Sum: 60
Practise
Add a fourth reading and calculate the average as a double.
Common mistake
The last valid index is count – 1. An out-of-bounds access has undefined behavior. The sizeof calculation does not work on an array parameter that has become a pointer.