Hello,
I have a conceptual code related to the C memory allocation model
if I have some code of this form, I will get a seg fault
int main()
{
char* p;
*(p+5)='A';
printf("%c\n",*(p+5));
}
But when I have some code of this form I do not get a seg fault
int main(int argc, char* argv[])
{
char* p=(char *)malloc(10);
*(p+15)='A';
printf("%c\n",*(p+15));
return 1;
}
But I am unable to understand the reason for this. In both the case I am writing to unallocated memory. So why am I not getting a seg fault in the 2nd case