摘要: 《高质量c++和c编程》7.4 指针参数是如何传递内存的一节中写道void GetMemory(char *p, int num) { p = (char *)malloc(sizeof(char) * num); } void Test(void) { char *str = NULL; GetMemory(str, 100); // str 仍然为 NULL strcpy(str, "hello"); // 运行错误 }无法返回内存,可以用如下方式void GetMemory2(char **p, int num) { *p = (char *)malloc(siz.. 阅读全文
posted @ 2013-07-25 22:09 没出没 阅读(1502) 评论(7) 推荐(2) 编辑