Fill This Form To Receive Instant Help
Homework answers / question archive / Give an example of how you might use an array in a program
Give an example of how you might use an array in a program. (A verbal explanation is sufficient).
For instance, in the C programming language, one-dimensional character arrays are used to store null-terminated strings.
Arrays permit efficient (constant-time, O(1)) random access but not efficient for insertion and deletion of elements (which are O(n), where n is the size of the array). Arrays are most appropriate for storing a fixed amount of data which will be accessed in an unpredictable fashion.
Another advantage of arrays that has become very important on modern architectures is that iterating through an array has good locality of reference, and so is much faster than iterating through (for instance) a linked list of the same size, which tends to jump around in memory.
One of the disadvantages of an array is that it has a single fixed size. Even though array size can be altered in many environments, this is an expensive operation.