How are elements of a traditional array generally stored in memory?

Options

  • A. In random memory locations
  • B. In contiguous memory locations
  • C. Only in stack memory
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. In contiguous memory locations

Detailed Explanation

Array elements are generally stored in contiguous memory locations. If the first element starts at a particular address, subsequent elements are placed at predictable offsets based on the size of each element. This memory organization enables efficient indexing and good cache locality. However, it also means that inserting elements into the middle may require shifting other elements. Contiguous storage is therefore closely related to the O(1) random-access advantage of arrays.