I get a weird result in the following C code.
int main()
{
int *p = (int *) malloc(100);
p[120] = 5;
printf("\n %d", p[120]);
}
Since I allocated only 100 bytes, this code should cause a segmentation error. However, it prints "5" and does not give any runtime error. Can someone explain the reason?
source
share