How to initialize a two-dimensional array in C++

coldplay.xixi
Release: 2023-01-04 09:38:53
Original
46577 people have browsed it

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.

How to initialize a two-dimensional array in C++

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.

How to initialize a two-dimensional array in C++

#2. Next, initialize different values ​​​​to the two-dimensional array n[3][4].

How to initialize a two-dimensional array in C++

#3. Finally, use a double loop to output each value in the array.

How to initialize a two-dimensional array in C++

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).

How to initialize a two-dimensional array in C++

#5. Run the program and you can see that the values ​​in the two-dimensional array are successfully output.

How to initialize a two-dimensional array in C++

#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?

How to initialize a two-dimensional array in C++

#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.

How to initialize a two-dimensional array in C++

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!