0
0
Cprogramming~10 mins

Two-dimensional arrays in C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a 2D array of integers with 3 rows and 4 columns.

C
int arr[3][[1]];
Drag options to blanks, or click blank then click option'
A4
B3
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 4 for the number of columns.
Confusing rows and columns sizes.
2fill in blank
medium

Complete the code to access the element in the second row and third column of a 2D array named matrix.

C
int value = matrix[[1]][2];
Drag options to blanks, or click blank then click option'
A1
B2
C3
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 for the row index.
Confusing row and column indices.
3fill in blank
hard

Fix the error in the code to correctly initialize a 2D array with 2 rows and 3 columns.

C
int arr[2][3] = {{ {1, 2, 3}, [1] }};
Drag options to blanks, or click blank then click option'
A{3, 4, 5, 6}
B{7, 8}
C{1, 2}
D{4, 5, 6}
Attempts:
3 left
💡 Hint
Common Mistakes
Using fewer or more elements than columns in a row.
Missing braces around the second row.
4fill in blank
hard

Fill both blanks to complete the nested loop that prints all elements of a 2D array named grid with 3 rows and 2 columns.

C
for(int i = 0; i < [1]; i++) {
    for(int j = 0; j < [2]; j++) {
        printf("%d ", grid[i][j]);
    }
    printf("\n");
}
Drag options to blanks, or click blank then click option'
A3
B2
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns counts.
Using wrong loop limits causing out-of-bounds access.
5fill in blank
hard

Fill all three blanks to create a 2D array named matrix with 2 rows and 3 columns, initialize it, and print the element at first row, second column.

C
int matrix[[1]][[2]] = {{ {1, 2, 3}, {4, 5, 6} }};
printf("%d\n", matrix[[3]][1]);
Drag options to blanks, or click blank then click option'
A2
B3
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong sizes for rows or columns.
Using 1 instead of 0 for the first row index.