gpt4 book ai didi

c - 我应该在哪里调用 Free() 函数?

转载 作者:太空宇宙 更新时间:2023-11-04 07:40:32 25 4
gpt4 key购买 nike

例如:


在空调中:

Head init(){
Head treeHead;
treeHead = malloc(sizeof (struct TreeHead));
treeHead->Root = malloc(sizeof (struct TreeNode));
return treeHead;}


在公元前:

Head treeHead;
treeHead = init();


我应该在 A.c 还是 B.c 中调用 free in init() 方法?

最佳答案

我会在 A.c 中定义一个函数:

void freeHead(Head head){
free(head->Root);
free(head);
return;
}

然后在B.c中适当的地方调用它:

freeHead(head);

关于c - 我应该在哪里调用 Free() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4544383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com