#include "cstdlib" #include"iostream" using namespace std; void GetMemory(char* p) { p = (char*)malloc(100); } void Test1(void) { char* str = NULL; GetMemory(str); strcpy(str,"helloword"); printf(str); }
void GetMemory(char** p) { (*p) = (char*)malloc(100); } void Test1(void) { char* str = NULL; GetMemory(&str); strcpy(str,"helloword"); printf("%s\n",str); free(str); }
void GetMemory2(char*& p)
{
p = (char*)malloc(100);
}
void Test1(void)
{
char* str = NULL;
GetMemory2(str);
strcpy(str,"helloword");
printf("%s\n",str);
free(str);
}