转载:
void GetMemory(char *p) GetMemory(str); 答:程序将崩溃,因为GetMemory不能传 递动态内存,因此str始终为NULL。strcpy 将会使程序崩溃。 | char *GetMemory(void) char *str = NULL; 答:可能是乱码,因为GetMemory返回的是栈内存的地址。str的值虽然不 为NULL,但是由于栈里边的内容已经被清楚,新内容不得而知。因此可能是乱码。 |
void GetMemory2(char **p, int num) { *p = (char *)malloc(num); } void Test(void) { char *str = NULL; GetMemory(&str, 100); strcpy(str, "hello"); printf(str); } 请问运行 Test函数会有什么样的结果? 答:能够输出hello,.内存泄漏 | void Test(void)
|