Is pointer arithmetic and mapping based on remote UB memory?

Fox example:

int* a = new int[10]; int* b = a; int* e = a + 10; delete[] a; for (; b != e; ++b); 

I know that the wrong disclosure pointer will be UB. But what about comparing and increasing?

Background

Here's the question , adding OP elements within a range-based loop, which could cause the iterator to become invalid. But it adds elements to the vector at the end, after which the iterator will be increased and compared, will not be dereferenced. Is it UB?

+5
source share

Source: https://habr.com/ru/post/1233467/


All Articles