Recall & Review
beginner
What is a two-dimensional array in C?
A two-dimensional array in C is like a table with rows and columns. It stores data in a grid format, where each element is accessed by two indexes: one for the row and one for the column.
Click to reveal answer
beginner
How do you declare a two-dimensional array of integers with 3 rows and 4 columns in C?
You declare it like this:
int arr[3][4]; This means the array has 3 rows and 4 columns.Click to reveal answer
beginner
How do you access the element in the 2nd row and 3rd column of a 2D array named
arr?You use
arr[1][2]. Remember, counting starts at 0, so the 2nd row is index 1 and the 3rd column 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 declared size of a 2D array?
Accessing outside the declared size causes undefined behavior. This means the program might crash, show wrong data, or behave unpredictably. Always stay within the array bounds.
Click to reveal answer
How do you declare a 2D array with 5 rows and 2 columns in C?
✗ Incorrect
The correct syntax uses square brackets for each dimension:
int arr[5][2];.What is the index of the first element in a 2D array in C?
✗ Incorrect
C arrays start at index 0, so the first element is at
[0][0].How do you access the element in the 3rd row and 1st column of
arr?✗ Incorrect
Indexing starts at 0, so 3rd row is index 2 and 1st column is index 0.
Which of these initializes a 2x2 array with all zeros?
✗ Incorrect
Using
{0} initializes all elements to zero.What is the risk of accessing arr[4][5] if arr is declared as int arr[3][4]?
✗ Incorrect
Accessing outside the declared size causes undefined behavior and can crash the program.
Explain how to declare, initialize, and access elements in a two-dimensional array in C.
Think of a table with rows and columns.
You got /3 concepts.
What are the dangers of accessing elements outside the bounds of a two-dimensional array in C?
Imagine trying to open a door that doesn't exist.
You got /4 concepts.