VECTORS

Diego Plascencia Sanabria A01229988

Vectors are sequence containers that can change in size. Its function is to store different values under a single name.

When using vectors in our programs we must include in the top of our program <vector>

The values can be in any data type (int, double, string…).

Vectors are declared with the following syntax:

           vector<type> variable_name (number_of_elements);

or

          vector<type> variable_name;  (the number of elements is optional).

Here are some example of vectors:

    vector<int> values (5);      // Declares a vector of 5 integers
    vector<double> grades (20);  // Declares a vector of 20 doubles
    vector<string> names;        // Declares a vector of strings,  

 

CC BY 4.0 VECTORS by diego plascencia is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.