Introduction to Vectors
Imagine you need to work with multiple values of the same type in your program - for example, a list of numbers or names. Instead of creating a separate variable for each value, we can use a vector.
A vector is like a list or container where we can store multiple values of the same type. For example:
- A list of school grades
- A list of student names
- A list of temperatures for the week
To use vectors, we must first add to the beginning of the program:
#include <vector>
We can do various things with vectors:
- Add a new value to the end.
- Find out how many values it has.
- Read a value at a specific position.
Instructions
In the following exercises, we'll learn to work with vectors!
Start programming for free
1/10