a problem about malloc()

1 . Thanks everyone who read the post.

2 . the programe is that :
#include <stdio.h>
#include <string.h>

void do_it(char *p)
{
p = (char *) malloc(100);

\(void \)strcpy\(p,"1234"\);

}

int main(void)
{
char *p;

do_it\(p\);

\(void \)printf\("p = %s \\n",p\);

return 0;

}

cc -g a.c -o a.out
./a.out
it will show that "memory fault(coredump)"

3 . Why ? I think that malloc() get memory from heap , and the heap can be seen at everywhere in the programe .In other words , it is "global" .

4 Then I write another programe. it works correctly .

#include <stdio.h>
#include <string.h>

char *do_it(void)
{
return ((char *) malloc(100));
}

int main(void)
{
char *p;

p = do_it\(\);

strcpy\(p, "asdfa"\);

\(void\) printf\("p = %s \\n",p\);

}

5 . Then , the point 4 declare that point 3 is correct , but it is not we want .
6 . Then I think the OS has changed the value p when do_it() function return

1 .I found the answer .
2 .First , I write another programe .
#include <stdio.h>
#include <string.h>

int main(void)
{
char *p;

p = \(char *\) malloc\(100\);

strcpy\(p, "asdfasdf"\);

return 0;

}

It works correctly .
3 . Why ? The point is that :
p is a local varible , when we call do_it(p) , the OS pass a copy of p to child function .Though we malloc memory to p in child function ,the p variable in main function is not changed .