gpt4 book ai didi

c - 尝试将内存分配给单独声明的指针变量时出错

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

<分区>

我已经通过以下方式声明了一个 char 指针:

School *student[10];

for(i=0;i<10;i++){
*student[i] = malloc(sizeof(Student)); <--- Error points here
}

我得到的错误是:

incompatible types when assigning to type 'struct Student' from type 'void*'

有人知道我为什么会收到此错误吗?

但是,如果我要在同一行中分配内存,那怎么会和星一样呢?例如:Student *name = malloc(sizeof(Student)); 为什么这样做有效?我有点困惑

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