2 dimensional array in c
To declare and initialize a 2-dimensional array in C, you can use the following syntax:
data_type array_name[row_size][column_size] = {
{value1, value2, value3, ...},
{value4, value5, value6, ...},
...
};
Here's an example of declaring and initializing a 2-dimensional array of integers with a size of 3 rows and 4 columns:
int matrix[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
You can access individual elements of the array using the row and column indices:
int element = matrix[row_index][column_index];
For example, to access the element in the second row and third column of the matrix above, you would use:
int element = matrix[1][2]; // element = 7
Remember that array indices start from 0, so the first row is at index 0, the second row is at index 1, and so on.
I hope this helps! Let me know if you have any further questions.