Book
Collection
Click for Table of Contents
© 2025 by Rance D. Necaise
C Primer for Python Programmers
Copyright © 2025
Rance D. Necaise

7.1 The Array Structure

At the hardware level, most computer architectures provide a mechanism for creating and using one-dimensional arrays. A one-dimensional array, as illustrated in Figure 7.1.1, is composed of multiple sequential elements stored in contiguous bytes of memory and allows for random access to the individual elements.

Figure 7.1.1. A sample 1-D array consisting of 11 elements.

As you may remember, the array structure looks very similar to Python's list structure. That's because the two structures are both sequences that are composed of multiple sequential elements that can be accessed by position. But there are two major differences between the array and the Python list. First, an array has a limited number of operations, which commonly include those for

  • array creation
  • reading a value from a specific element, and
  • writing a value to a specific element.

The list, on the other hand, provides a large number of operations for working with the contents of the list. Second, the list can grow and shrink during execution as elements are added or removed while the size of an array cannot be changed after it has been created.

Question 7.1.1

What do vectors and arrays have in common?

They are both indexed sequences in which the elements are accessed by index or position.