C语言传指针类型的形参

今天在牛客网上做C语言专项练习题,遇到一个“函数传指针类型的形参”的题,我做错了,正确的为下面代码:

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

void getmemory(char** p)  {
    *p=(char *) malloc(100);
    strcpy(*p,"hello world");
}

int main( )
{
    char *str=NULL;
    getmemory(&str);
    printf("%s
",str);
    free(str);
    return 0;
}
原文地址:https://www.cnblogs.com/sinodragon21/p/14381949.html