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

10.7 Dynamic 2-D Arrays

Most computer architectures provide a mechanism at the hardware level for creating and using one-dimensional arrays. Programming languages need only provide appropriate syntax to make use of a 1-D array. Multi-dimensional arrays are not handled at the hardware level. Instead, the programming language typically provides its own mechanism for creating and managing multi-dimensional arrays.

As you have seen in the previous sections, the C programming language provides a direct method for allocating and working with static 2-D arrays and arrays of higher dimensions. If you need to allocate and use a dynamic 2-D array, you must provide the code to allocate the dynamic memory for the array and for accessing the individual elements.

There are several approaches that we can use to store and organize the data for a 2-D array. Two of the more common approaches include the use of a single 1-D array to physically store the elements of the 2-D array by arranging them in order based on either row or column, whereas the other uses an array of arrays. We begin with the use of a single array to store the entire contents of a 2-D array.