S
sam_cit
Hi Everyone,
I have the following program unit,
#include <stdlib.h>
int main()
{
char *p = (char*)malloc(100);
if(p==NULL)
{
printf("...null...\n");
}
else
{
printf("...success...\n");
printf("1.%d\n",p[10]);
memset(p,0,101);
printf("2.%d\n",p[10]);
free(p);
printf("3.%d\n",p[101]);
}
}
I used gcc on Solaris OS and i get the following output,
1.0
2.0
3.0
Shouldn't the following statements cause a segmentation fault?
printf("3.%d\n",p[101]);
//As i'm referring to p after the memory is deallocated
memset(p,0,101);
//As access to memory is beyond the allocated portion.
Thanks in advance!!!
I have the following program unit,
#include <stdlib.h>
int main()
{
char *p = (char*)malloc(100);
if(p==NULL)
{
printf("...null...\n");
}
else
{
printf("...success...\n");
printf("1.%d\n",p[10]);
memset(p,0,101);
printf("2.%d\n",p[10]);
free(p);
printf("3.%d\n",p[101]);
}
}
I used gcc on Solaris OS and i get the following output,
1.0
2.0
3.0
Shouldn't the following statements cause a segmentation fault?
printf("3.%d\n",p[101]);
//As i'm referring to p after the memory is deallocated
memset(p,0,101);
//As access to memory is beyond the allocated portion.
Thanks in advance!!!