I'm working on a program using arrays and I'm trying to figure out
First, with the following array declaration, what is the value stored in the scores[2][2]
element?
int scores[3][3] = { {1, 2, 3} };
And also with this array declaration, what is the value stored in the scores[2][3]
element?
int scores[5][5] = {5};
Could someone please explain this for me.
Here is how we can initialize a 2-dimensional array in Java. int[][] a = { {1, 2, 3}, {4, 5, 6, 9}, {7}, }; As we can see, each element of the multidimensional array is an array itself.
A 2D character array is declared in the following manner: char name[5][10]; The order of the subscripts is important during declaration. The first subscript [5] represents the number of Strings that we want our array to contain and the second subscript [10] represents the length of each String.
Two-dimensional arrays may be initialized by specifying bracketed values for each row. int [,] a = new int [4,4] { {0, 1, 2, 3} , {4, 5, 6, 7} , {8, 9, 10, 11} , {12, 13, 14, 15} }; The following is an example showing how to work with two-dimensional arrays in C#.
The 2D array is organized as matrices which can be represented as the collection of rows and columns. However, 2D arrays are created to implement a relational database lookalike data structure.
int scores[3][3] = { {1, 2, 3} };
is equivalent to:
int scores[3][3] = { {1, 2, 3}, {0, 0, 0}, {0, 0, 0}};
The other one is similar. You know the answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With