This is the 12th day of my participation in Gwen Challenge


An array of

A one-dimensional array
The sizeof an array is sizeof(arr). 2. Get the first address of the array in memoryCopy the code
/** declare an array */
//type arrayName [ arraySize ];
int a[100];

/* Initialize */
// Specify the array length
double balance[5] = {1000.0.2.0.3.4.7.0.50.0};
double balance[5] = {1000.0};// Not all initials. defaults to 0
// The length is not specified
double balance[] = {1000.0.2.0.3.4.7.0.50.0};

* / / * * visit
// Access with subscripts (starting from 0)
cout<<balance[0]<<endl;

Copy the code
2 d array
The sizeof an array is sizeof(arr). 2. You can obtain the first address of the two-dimensional array in memoryCopy the code
/** The simplest form of a multidimensional array is a two-dimensional array. A two-dimensional array is, in essence, a list of one-dimensional arrays. ArrayName [x][y]; arrayName [x][y]; * /


/** Initializes a two-dimensional array */
int a[3] [4] = {{0.1.2.3},/* Initializes line 0 */
 {4.5.6.7},/* Initialize the row with index 1 */
 {8.9.10.11}   /* Initialize the line with index 2 */
};

// Internally nested parentheses are optional, and the following initialization is equivalent to the above:
int a[3] [4] = {0.1.2.3.4.5.6.7.8.9.10.11};


/** Access a two-dimensional array element */
// Elements in a two-dimensional array are accessed by using subscripts (i.e. the row and column indexes of the array). Such as:
int val = a[2] [3];

Copy the code
Dynamic array — Vertor
Vector container vector
  1. Dynamic array, run time set length
  2. Has a quick index of arrays
  3. You can insert and delete
Define and initialize
vector <double > vec1;
vector <string > vec2(5);// Assume the data width is 5
vector <int > vec3(20.998)// The default 20 elements are 998 each

Copy the code
Common operations

First iteration iterator