I'm freeing a variable I allocated using malloc, but after I've freed it I try to access it and it still works fine.
I would expect a segmentation fault when accessing this memory but I dont get one.
Here is a simple example to show the problem:
#include <stdio.h>
#include <stdlib.h>
int main() {
    int *arr = (int*)malloc(5*sizeof(int));
    arr[0] = 2;
    arr[4]=9;
    free(arr);
    printf("%d\n",arr[4]);
    return 0;
}
The output is 9.
 
     
    