What is the initialization method of C++ array
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