int arr[4] = {0, 1, 2, 3};
int *p = arr + 5; // undefined behavior
int k, i;
for (i = 0; i < 10; i++) {
k = k + 1; // What is k?
}
vector<int> x = { 1, 2, 3 };
int j = 0;
for (auto it = x.begin(); it != x.end(); ++it) {
x.push_back(j); // Makes iterator invalid.
j++;
cout << j << " .. ";
}
Iterators are invalidated by some operations that modify a std::vector.
if (x == 5) { // The "Check"
y = x * 2; // The "Act"
// If another thread changed x
// in between "if (x == 5)" and
// "y = x * 2" above, y will not be
// equal to 10.
}
Two good books, one free: