One: Define
The definition of array is the same as that defined in the C language. To specify a type, name, and size, the size should be a constant value. For example:
const int seq_size=18;
int pell_seq[seq_size];
The initialization of a vector must contain a header file, which indicates the element type within the angle brackets after the class name, and the size in parentheses, where the size is not necessarily a constant. For example:
#include <vector>
Vector<int>pell_seq (seq_size);
Two: Initialize
The initialization of an array can be done using the method of the specified list. The specified value becomes part or all of the elements of the array. For example:
int elem_seq[seq_size]={1,2,3,4,5};
The number of elements in the list should not exceed the size of the array, and if less, the remaining elements will be initialized to 0
Vector initialization is currently available in 2 ways:
The first of these is:
Vector<int>elem_seq (seq_size);
Elem_seq[0]=1;
elem_seq[1]=2;
Write out all the element values in turn
The second type is:
Use a known quantity group to initialize the vector
int elem_vals[seq_size]={1,2,3,4};
Initialize the elem_seq with the value of elem_vals;
Vector <int>elem_seq (elem_vals,elem_vals+seq_size);
Three: Differences
The vector knows what size it is,
In any program, the number of elements contained in the vector is returned as long as the elem_seq.size () statement is used. No additional definition is required.
How to use array and vector