小编din*_*abu的帖子

在 C 中使用 free() 时出现无效(中止)核心转储错误

这是代码:任何人都可以解释这个问题我如何在 main 中释放 s 的内存

char *get(int N)
{
    char *s=malloc(10*sizeof(char));  
    s="hello";  
    return s;  
}
 int main()  
{  
    char *s=get(4);  
    printf(s);  
    free(s);  
}
Run Code Online (Sandbox Code Playgroud)

c free pointers

1
推荐指数
1
解决办法
319
查看次数

标签 统计

c ×1

free ×1

pointers ×1