I just wrote code to copy a vector value of another vector and when I edit the second vector the original one should be changed.
Here is the code confusing me:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<int>a = {1,2,3,4,5};
vector<int>* b = new vector<int>(6);
b = &a;
(*b).push_back(7);
for (int i = 0; i <= 6; i++) {
cout << a[i];
}
cout << endl;
for (int i = 0; i <= 6; i++) {
cout << (*b).at(i);
}
delete b;
}
the question is why I get this result when I run the program:
1234570
123457
Why don't I get the last zero in both of them?