做个标记,指针的指针的应用

程序1

void myMalloc(char *s) //我想在函数中分配内存,再返回

{

  s=(char *) malloc(100);

}

void main()

{

  char *p=NULL;

  myMalloc(p); //这里的p实际还是NULL,p的值没有改变,为什么?

  if(p) free(p);

}

程序2

void myMalloc(char **s)

{

  *s=(char *) malloc(100);

}

void main()

{

  char *p=NULL;

  myMalloc(&p); //这里的p可以得到正确的值了

  if(p) free(p);

}

原文地址:https://www.cnblogs.com/linmzh/p/2751471.html