N
neilcancer
i come from china,and i'm sorry that my english is very poor.
now i'm studing data structure and i met some problem about c language.
could you tell me what will happen after i use free()? i mean once i
use free() on a pointer,what will the pointer points to ?
for example:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *p;
if(!p) printf("good");
else printf("fail");
p=(int *)malloc(100);
if(p) printf("\n\ngood");
else printf("\n\nfail");
free(p);
if(!p) printf("\n\ngood");
else printf("\n\nfail");
*p=100;
printf("\n\n%d",*p);
}
the result is:
fail
good
fail
100
why?
now i'm studing data structure and i met some problem about c language.
could you tell me what will happen after i use free()? i mean once i
use free() on a pointer,what will the pointer points to ?
for example:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *p;
if(!p) printf("good");
else printf("fail");
p=(int *)malloc(100);
if(p) printf("\n\ngood");
else printf("\n\nfail");
free(p);
if(!p) printf("\n\ngood");
else printf("\n\nfail");
*p=100;
printf("\n\n%d",*p);
}
the result is:
fail
good
fail
100
why?