Vector basics in C++
Level 3118 keystrokes
Creates a vector<int> with five elements and prints its size (5), its first element (1) and its last element (5).
C++ code
// vector is a resizable array; the initializer list gives it 5 elements1vector<int> nums = {1, 2, 3, 4, 5};// size() returns the number of elements: 52cout << nums.size() << endl;// [] accesses an element by index; indices start at 0, so this prints 13cout << nums[0] << endl;// back() returns the last element: 54cout << nums.back() << endl;Output
5 1 5
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.
<× 13,× 4;× 4.× 2(× 2)× 2[× 1]× 1{× 1}× 1