CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #136

vector::at Versus operator[]

easyExceptions

scores has three elements. What is true about scores.at(5) compared with scores[5]?

📄 Code

1#include <iostream>
2#include <stdexcept>
3#include <vector>
4 
5int main() {
6 std::vector<int> scores = {70, 85, 90};
7 try {
8 std::cout << scores.at(1) << "\n";
9 std::cout << scores.at(5) << "\n";
10 } catch (const std::out_of_range&) {
11 std::cout << "index 5 is out of range\n";
12 }
13 return 0;
14}