1/29
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Array Definition
A data structure containing a number of data values, all of which have the same type.
Two Core Requirements of Arrays
1) All elements must be the same data type. 2) Each element must have a unique index.
Array Declaration Syntax
Data-type
Size Declarator
The integer constant expression inside the [ ] that indicates the number of elements in an array.
Array Memory Allocation
Values are stored in adjacent (contiguous) memory locations.
First Element Index
The index of the first element in any C++ array is always 0.
Last Element Index
The index of the last element in an array of size 'n' is n - 1.
Array Bounds Checking
C++ does not perform array bounds checking; using an invalid index leads to runtime errors or memory corruption.
Array Initialization List
Initializing an array at declaration using a comma-separated list inside braces { }.
Partial Initialization
If an array is partially initialized, the remaining uninitialized elements are set to zero.
Implicit Array Sizing
Determining the size of an array automatically by the number of items in the initialization list.
Array Assignment Rule
You cannot assign one array to another using the = operator; you must copy element-by-element.
Displaying Array Contents
Except for char arrays, you must use a loop to display each element of an array.
Range-Based for Loop (C++ 11)
A loop that iterates once for each element in an array: for (dataType rangeVar : arrayName).
Range-Based Loop with Reference (&)
Required if you want to modify the actual values inside the array while using a range-based loop.
Parallel Arrays
Two or more arrays that contain related data, where elements at the same subscript are related.
2D Array Declaration
Data_Type arrayName[rows][cols];
2D Array Memory Layout
Conceptually a grid, but stored in memory as a single continuous block of rows.
2D Array Initialization
Initialized row by row; nested braces are recommended for clarity.
Multi-dimensional Arrays
C++ allows arrays with any number of dimensions, such as 3D (rows, columns, and depth).
STL Vector
A dynamic data structure that can grow or shrink in size during execution.
Vector Header File
The preprocessor directive #include
push_back(value)
A vector member function that adds an element to the end of the vector.
pop_back()
A vector member function that removes the last element from a vector.
size() Member Function
Returns the number of elements currently stored in the vector.
at(index) Member Function
Returns the value of the element at a specific position, with built-in bounds checking.
capacity() Member Function
Returns the maximum number of elements a vector can store without allocating more memory.
clear() Member Function
Removes all elements from a vector, making it empty.
empty() Member Function
A boolean function that returns true if the vector contains no elements.
Subscript Operator [] with Vectors
Vectors can use [] just like arrays, but it does not provide bounds checking like at() does.