小编odi*_*n19的帖子

释放通过malloc获得的结构数组

所以我有这个结构:

typedef struct type {
      int a;
      char* b;
} type;
Run Code Online (Sandbox Code Playgroud)

main程序中,我制作了这些结构的2个数组,并使用malloc():

type *v;
type *w;
v=malloc(50*sizeof(type));
w=malloc(50*sizeof(type));
Run Code Online (Sandbox Code Playgroud)

现在,如果我想释放这些结构数组是正确的:

free(v);
free(w);
Run Code Online (Sandbox Code Playgroud)

c malloc free

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

当您调用具有返回值的函数而不将其分配给任何变量时会发生什么?

#include <stdio.h>
#include <stdlib.h>

int f(int x) {
    return x;
}

int main ( int argc,char * argv[]) {
    int a=4;
    f(a);
    printf("PASSED!\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当你打电话f(a)而没有把它分配给任何东西时会发生什么?

c function return-value

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

标签 统计

c ×2

free ×1

function ×1

malloc ×1

return-value ×1