Home>Article>Backend Development> How to initialize a two-dimensional array in C++
C Method to initialize a two-dimensional array: first define two integer variables and initialize different values for the two-dimensional array; then use a double loop to output each value in the array; finally use curly brackets The enclosed numbers are assigned directly.
The operating environment of this article: Windows 7 system, Dev-C 5.2.0.3 version, Dell G3 computer.
[Related learning recommendations:C language tutorial video]
C Method to initialize a two-dimensional array:
1 , First, define two integer variables to control the output of the two-dimensional array.
#2. Next, initialize different values to the two-dimensional array n[3][4].
#3. Finally, use a double loop to output each value in the array.
4. Two-dimensional arrays can be directly assigned using numbers enclosed in curly brackets. Each pair in the inner curly brackets represents a row, and the value in each pair of inner curly brackets Represents each value in a row (note that the value in curly brackets should correspond to the number of elements in the two-dimensional array).
#5. Run the program and you can see that the values in the two-dimensional array are successfully output.
#6. What will happen if you only assign values to some elements in the two-dimensional array, for example, only assign an initial value to one row?
#7. Run the program and you can see that in the array, only the first row has an initial value set, and the values in other rows are all 0.
The above is the detailed content of How to initialize a two-dimensional array in C++. For more information, please follow other related articles on the PHP Chinese website!