几个内存相关面试题(c/c++)
void GetMemory(char *p){p=(char*)malloc(100);}void Test(void){char *str = NULL;GetMemory(str);strcpy(str,”helloworld”);printf(str);}请问运行Test函数会有什么样的结果?答:程序崩溃。因为GetMemory并不能传递动态内存,Test函数中的str一直都是NULL。strcpy(str,”helloworld”);将使程序崩溃。char *GetMemory(void){char p[]=”helloworld”;return p;}void Test(void){char *str = N...