- /*动态内存传递
- 1 在C中,使用指向指针的指针解决这个问题
- 2 在C++中,使用传递指针的引用
- 3 使用函数返回值来传递动态内存
- */
void GetMemory1(char **p,int num){ *p=(char*)malloc(sizeof(char)*num); } void GetMemory2(char *&p,int num){ p=(char*)malloc(sizeof(char)*num); } char* GetMemory3(int num){ char *p=(char*)malloc(sizeof(char)*num); return p; } int _tmain(int argc, _TCHAR* argv[]) { char *str1=NULL; char* str2=NULL; char *str3=NULL; char *str4=NULL; GetMemory1(&str1,20); GetMemory2(str2,40); str3=GetMemory3(20); strcpy(str1,"GetMemory1"); strcpy(str2,"GetMemory2"); strcpy(str3,"GetMemory3"); cout<<"str1="<<