今天在牛客網上做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\n",str); free(str); return 0; }