The following code snippet prints beyond the allocated the range.It is printing <127, beyond that segmentation fault occurs. But my intention is beyond allocated range it should get segmentation fault,it is not happening why?. Please suggest.
int main ()
{
char *ptr;
char i = 0;
ptr = malloc (5);
for (i = 0; i < 127; i++)
*(ptr + i) = i;
for (i = 0; i < 127; i++)
printf ("value %d\n", *(ptr + i));
return 0;
}