函数返回的问题..
今天做数据结构作业。。。遇到点问题..
//这个是主函数里调用的语句..
PrintStudentList(Order(ShellSort(Copy(A,n), n), n), n);
被调用函数大致如下:
StudentList Copy(StudentList A, int n)
{
StudentList B = (StudentList)malloc(n*sizeof(student));
.....//A复制到B
return B;
}
StudentList ShellSort(StudenList A, int n);
StudentList Order(StudentList A, int n);
....
我想问的是Copy中的B在return 后,它的生存期不就结束了么?为什么我那样写程序还能运行?
..是不是那个copy函数的最后没有用free把malloc分配的空间给释放掉,就算是内存泄漏了..就算函数返回了,堆里的空间还是占用着是吧?所以外层函数ShellSort()Order()之类的还可以访问那个空间里的内容?