0
0
Cprogramming~5 mins

Two-dimensional arrays in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aint arr[5][2];
Bint arr[2][5];
Cint arr(5,2);
Dint arr[5,2];
What is the index of the first element in a 2D array in C?
A[0][0]
B[1][1]
C[0][1]
D[1][0]
How do you access the element in the 3rd row and 1st column of arr?
Aarr[0][1]
Barr[2][0]
Carr[1][2]
Darr[3][1]
Which of these initializes a 2x2 array with all zeros?
Aint arr[2][2] = {{0, 0}, {0, 0}};
Bint arr[2][2] = {1};
Cint arr[2][2] = 0;
Dint arr[2][2] = {0};
What is the risk of accessing arr[4][5] if arr is declared as int arr[3][4]?
AIt returns zero
BNo risk, it's valid
CUndefined behavior, possible crash
DIt automatically resizes the array
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.