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

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

1/10

Introduction to Vectors | Start Coder