Vector Pop Back in C++

Level 266 keystrokes

Removes the last element of the vector {1, 2, 3} with pop_back() and prints the new size, 2.

C++ code

// Creates a vector with three elements
1vector<int> v = {1, 2, 3};
// pop_back() removes the last element (3), leaving {1, 2}
// It returns nothing, so read back() first if you need the value
2v.pop_back();
// Prints the new size, 2
3cout << v.size() << endl;

Output

2
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C++ code and how often they appear.

  • <× 5
  • ;× 3
  • ,× 2
  • .× 2
  • (× 2
  • )× 2
  • _× 1
  • {× 1
  • }× 1
  • =× 1

More C++ examples at level 2

← C++ typing practice