Arrays and Fixed-Size Collections
Fixed-size collections in C++: built-in arrays, std::array, safe indexing, traversal, multidimensional layouts, and practical fixed-capacity techniques.
C-Style Arrays
C-style arrays are contiguous regions of memory where you store exactly (n) elements of type T. The size of the array, (n), is determined at compile time. int s…
Array Bounds and Common Indexing Errors
The valid indexes of a C style array are the numbers from 0 to one less than the number of elements. Every access must be within those bounds. Outside of those…
Looping Through Arrays
To visit each element of a C style array, the natural way is a loop that increases by one through each valid index from zero up to, but not including, the size…
Searching, Counting, and Updating Array Values
An array search is simply a traversal through each of its elements until the desired element is found, or until all elements have been looked at. Since C style…
Partially Filled Arrays and Tracking Used Elements
A C style array always takes up a fixed amount of memory. It stores a predetermined number of elements, determined by how it's declared. Often, the number of va…
Multidimensional Arrays
Represent rectangular data with two-dimensional C-style arrays, access cells by row and column, and traverse the structure with nested loops.
Working with std::array and Comparing It with C-Style Arrays
The std::array is a fixed size collection that improves upon a C style array, while preserving the same basic behavior. The number of elements is fixed at compi…
Arrays of std::string and Other Objects
Arrays can hold any single type of item, including std::string objects and objects of other class types. Each item is a complete object, and an array simply sto…