0
0
C++programming~5 mins

Multi-dimensional arrays in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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++?
Aint arr[2,3,4];
Bint arr[3][4][2];
Cint arr[2][3][4];
Dint arr(2,3,4);
What is the index of the first element in any dimension of a C++ array?
A1
BDepends on the array
C-1
D0
Which of these is a valid way to access an element in a 2D array named arr?
Aarr[2][3]
Barr(2,3)
Carr[2,3]
Darr{2}{3}
What does the following code do? <br> int arr[2][2] = {{1, 2}, {3, 4}};
ACauses a syntax error
BCreates a 2x2 array with values 1,2 in first row and 3,4 in second row
CCreates an empty 2D array
DCreates a 1D array with 4 elements
What is the risk of accessing arr[5][5] if arr is declared as int arr[3][3];?
AUndefined behavior, possible crash or wrong data
BCompiler error
CNo risk, it returns 0
DIt will resize the array automatically
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.