C TutorialLesson 18Free preview
C Arrays
This lesson is part of C · All levels
Summary
An array is a container for storing many values of the same type in one named variable, accessible via an index number starting at 0. The size of the array must be a constant known at compilation and written in square brackets, e.g. int numbers[5]. The last element of an array n-sized has an index of n-1, so access to the index of n will cross the memory limit. Arrays are very efficient at processing data sets sequentially and repeatedly.
Key points
- The array index in C always starts from 0
- The last element of an array of n dimensions is at the n-1 index
- All elements in an array must be of the same type
- Access outside the index (out of bounds) is dangerous and unimpeded compiler
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.