I'm trying to wrap my head around why this works. As far as I understand when i dynamically allocate 3 ints it shouldn't let me add more after index 2 but the code below compiles and runs perfectly well. Why is this?
#include <iostream>
int main() {
int* nums = new int[3];
nums[0] = 5;
nums[1] = 6;
nums[2] = 5;
nums[3] = 7;
nums[4] = 8;
for(int i = 0; i <= 4; i++) {
std::cout << nums[i] << std::endl;
}
delete nums;
return 0;
}