C-malloc不分配请求的内存

时间:2018-08-16 16:05:03

标签: c malloc heap-memory

我已经创建了一个结构,并且想对该结构进行数组制作,我尝试使用malloc()分配内存,但是它似乎并未分配所请求的内存。

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

typedef struct Players{
    int level_;
    char name_[15];
    float progress_;
    float health_;
} player;

int main()
{
    player *n =  malloc(2 * sizeof(player));
    printf("%d \n", sizeof(n));

    free(n);

    return 0;
}

分配的内存是8,而不是56。

我想念什么吗?

0 个答案:

没有答案
相关问题