#include<stdio.h> #include<stdlib.h> #include<string.h> char* GetMemory() { return (char *)malloc(100); } int main() { char*str = GetMemory(); //GetMemory(str); strcpy(str, "hello word"); printf("%s\n", str); return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> void GetMemory(char **p) { *p = (char *)malloc(100); } int main() { char*str = NULL; GetMemory(&str); strcpy(str, "hello word"); printf("%s\n", str); return 0; }