Vector Declaration in C++

Level 264 keystrokes

Creates a vector<int> with five values and prints its number of elements, 5, using size().

C++ code

// vector<int> is a resizable array of ints, here filled with 1 to 5
1vector<int> nums = {1, 2, 3, 4, 5};
// size() returns the current number of elements, so 5 is printed
2cout << nums.size() << endl;

Output

5
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
  • ,× 4
  • ;× 2
  • .× 1
  • (× 1
  • )× 1
  • {× 1
  • }× 1
  • =× 1
  • >× 1

More C++ examples at level 2

← C++ typing practice