We can access the data inside a vector using indices and the bracket notation ([]), just like we do for static arrays.
Vectors also use zero-based indexing, so the first element in a vector has an index of 0.
vector<int> array = {50, 60, 70};
cout << array[0] << endl; // Output: 50
int data = array[1];
cout << data << endl; // Output: 60
Assignment
Follow the Coding Tutorial and let's play with some arrays.
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
