Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the initialization method of C++ array

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "what is the method of initializing C++ array". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

C++ initialization array method: 1, define the array and then assign values to the array, syntax "data type array name [length]; array name [subscript] = value;"; 2, define the array when initializing the array, syntax "data type array name [length] = [values list]".

The operating environment of this tutorial: windows7 system, Craft 17 version, Dell G3 computer.

Sometimes it is more appropriate to set a variable value in a program than to enter a variable value. However, writing separate assignment statements for each element of an array may mean a large amount of input, especially for large arrays.

For example, look at a program:

# include # include using namespace std;int main () {const int NUM_MONTHS = 12; int days [num _ MONTHS]; days [0] = 31; / / January days [1] = 28; / / February days [2] = 31; / / March days [3] = 30; / / April days [4] = 31; / / May days [5] = 30; / / June days [6] = 31; / / July days [7] = 31 / / August days [8] = 30; / / September days [9] = 31; / / October days [10] = 30; / / November days [11] = 31; / / December for (int month = 0; month < NUM_MONTHS; month++) {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report