1 void myfunc(char** param){
2 ++param;
}
int main(){
3 char* string = (char*)malloc(64);
4 strcpy(string, "hello_World");
5 myfunc(&string);
6 myfunc(&string);
7 printf("%s\n", string);
// ignore memory leak for sake of quiz
8 return 0;
}
Run Code Online (Sandbox Code Playgroud)
该程序应该打印什么?
A)hello_world
B)ello_world
C)llo_world
D)lo_world
E)非法内存访问,未定义的行为
我的解剖,一行一行.请校对,几周前我刚开始学习C,指针/内存管理开始在我的大脑中"点击"!
现在,有几个问题.如何更改此代码以使b),c),d),甚至e)成为正确的答案?另外,由于在空字符之后存在2个"不同步"的内存字节,因为指针移位超过2个字节,所以它们正在讨论内存泄漏吗?如果没有,他们是什么意思?