Recall & Review
beginner
What is a multi-dimensional array in C++?
A multi-dimensional array is an array of arrays. It allows storing data in a table-like structure with rows and columns, such as a 2D array.
Click to reveal answer
beginner
How do you declare a 2D array with 3 rows and 4 columns in C++?
You declare it like this:
int arr[3][4]; This creates 3 rows and 4 columns of integers.Click to reveal answer
beginner
How do you access the element in the 2nd row and 3rd column of a 2D array named
arr?Use
arr[1][2]. Remember, indexing starts at 0, so row 2 is index 1 and column 3 is index 2.Click to reveal answer
intermediate
How can you initialize a 2D array with values at the time of declaration?
You can write:
int arr[2][3] = {{1, 2, 3}, {4, 5, 6}}; This sets the first row to 1,2,3 and the second row to 4,5,6.Click to reveal answer
intermediate
What happens if you try to access an element outside the bounds of a multi-dimensional array?
Accessing outside the array bounds causes undefined behavior. This can lead to wrong data, crashes, or security issues.
Click to reveal answer
How do you declare a 3D array with dimensions 2x3x4 in C++?
✗ Incorrect
The correct syntax uses square brackets for each dimension: int arr[2][3][4];
What is the index of the first element in any dimension of a C++ array?
✗ Incorrect
C++ arrays start indexing at 0 for every dimension.
Which of these is a valid way to access an element in a 2D array named arr?
✗ Incorrect
Use square brackets for each dimension: arr[2][3].
What does the following code do? <br>
int arr[2][2] = {{1, 2}, {3, 4}};✗ Incorrect
The code initializes a 2x2 array with the given values in each row.
What is the risk of accessing arr[5][5] if arr is declared as int arr[3][3];?
✗ Incorrect
Accessing outside declared bounds causes undefined behavior.
Explain how multi-dimensional arrays are stored in memory in C++ and how indexing works.
Think about how a 2D table is stored as a long list in memory.
You got /3 concepts.
Describe how to declare, initialize, and access elements in a 2D array in C++.
Use examples with small arrays to explain.
You got /3 concepts.