C++ Vector Operation Access Elements

#include <iostream>
#include <vector>

int main() {
    // Step 1: Declare a vector of integers
    std::vector<int> myVector;

    // Step 2: Add elements to the vector
    myVector.push_back(10);
    myVector.push_back(20);
    myVector.push_back(30);
    myVector.push_back(40);

    // Step 3: Access elements using the subscript operator []
    int firstElement = myVector[0];
    int secondElement = myVector[1];

    // Step 4: Access elements using the at() function
    int thirdElement = myVector.at(2);
    int fourthElement = myVector.at(3);

    // Step 5: Display the accessed elements
    std::cout << "First Element: " << firstElement << std::endl;
    std::cout << "Second Element: " << secondElement << std::endl;
    std::cout << "Third Element: " << thirdElement << std::endl;
    std::cout << "Fourth Element: " << fourthElement << std::endl;

    return 0;
}