|
|
|
|
|
by notriddle
3456 days ago
|
|
> C++11 and beyond is just as safe as any language. That's just not accurate. This is UB, despite being done entirely using modern C++ API: #include <iostream>
#include <vector>
using namespace std;
int main() {
std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
for (int i : v) {
v.push_back(5);
std::cout << i << std::endl;
v.push_back(6);
}
return 0;
}
I ran it on https://code.sololearn.com/caR4o14MOCWr/#cpp and got this output: 1
8519872
3
4
|
|