When I create a dynamic Array :
int *arr = (int *) malloc( 4 * sizeof(int) );
So it should hold like 4 integers ( maybe 2 or 3 more for space issues maybe ) but why does that work :
for ( int x = 0; x < 30000; x++) {
arr[x] = x;
}
I mean there shouldn't be so much space for 30.000 variables and its working just fine, what could be be the reason ? Does it automatic realloc like with c++ std::vector or how can I understand it ?
If I put the loop range like 50.000 it will crash, but it should even crash like at index a[100] or before, because the array is 4 elements big.
I am using gnu / linux if that matters.
I try very hard to understand it.
Please help