运行代码
运行结果
程序崩溃
程序解释
首先,函数为按值传递,所以p和str指向的是同一个NULL;
GetMemory函数执行完后,为p指向的空间增加了内存空间,但str仍然指向NULL;
要修改实参,就要传递实参的地址,因此需要传递二级指针,修改如下:
程序崩溃
首先,函数为按值传递,所以p和str指向的是同一个NULL;
GetMemory函数执行完后,为p指向的空间增加了内存空间,但str仍然指向NULL;
要修改实参,就要传递实参的地址,因此需要传递二级指针,修改如下: