So today i was testing out some code for a university lab and i found out that when dynamically allocating an array of 6 integers in C++, is possible to read and write to the 7th and 8th positions of the dynamically allocated array (i.e., 6th and 7th index) as seen in the picture below.
Now of-course if i try replicate this with a static array i will receive a runtime error as expected.
So the question is, why does this work and what are some pitfalls when setting this in use?