Day 23 Recap Questions
  1. What is a template in C++?
  2. What is the standard template library (STL)?
  3. How do you iterate over a std::vector and print out its elements?
  4. What is an iterator in C++?
  5. How do you add an element to an existing vector.
  6. What’s the difference between an iterator and a const_iterator?
  7. (Bonus) What is the output of the program below?
#include <iostream>
#include <vector>

using std::cin; using std::cout; using std::endl;
using std::vector;

int main() {

  vector<double> numbers;
  for (int i = 1; i <= 10; i++) {
    if (i % 2 == 1)
      numbers.insert(numbers.begin(), i / 2.0);
    else
      numbers.push_back(i * 2.0);
  }

  vector<double>::iterator it = numbers.begin();
  cout << "first == " << *it << endl;
  cout << "middle1 == " << *(it + 4) << endl;
  cout << "middle2 == " << *(it + 5) << endl;
  cout << "last == " << *(it + 9) << endl;
  
}