VECTORS Question 8

Last Updated :
Discuss
Comments

What will the following code print?

C++
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    vector<int> v = {1, 2, 3, 4, 5};
    for (int x : v)
        x = x + 2;
        
    for (int x : v)
        cout << x << " ";
    return 0;
}

1 2 3 4 5

2 4 6 8 10

2 4 5 6 7

Compiler Error

Share your thoughts in the comments