#include <stdio.h>
#include <string.h>
#include <malloc.h>
void  new(char *p)
{
         p=(char *)malloc(100);
}
main()
{
        char  *p1=NULL;
         new(p1);
         strcpy(p1,"编程学习");
          printf("%s\n",p1);
}
        在上面的程序中,用户可以很容易发现,变量p1是在栈上开辟的空间,而函数new中的指针p是指向堆中开辟的空间。所以,调用函数new'后,代码段“strcpy(p1,"编程学习");”中的p1仍然是初始化时的变量p1。
         这样,当用户向p1中复制字符串时,将发生错误。