经典笔试真题讲解1
题目一:
void GetMemory(char*p){
p=(char*)malloc(100);
}
void Test(void){
char*str=NULL;
GetMemory(str);
strcpy(str,"hello world");
printf(str);
}
请问运行Test函数会有什么样的结果?
答案:非法访问
【解析】进入Test函数之后,先初始化了str的指针指向NULL,后调用了GetMemory函数,跳出函数后,进行字符串
原创
2022-03-29 18:53:14 ·
565 阅读 ·
0 评论