小编Agn*_*oc 的帖子

使用指针将内存分配给结构

我有以下链表:

struct node {
    int d;
    struct node *next;   
};

int main()
{
    struct node *l = 0;
    struct node *k = l;
    k = malloc(sizeof(struct node));
    /* l->d = 8; */
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么注释代码使用错误?我不明白为什么内存没有分配给k指向同一个节点的节点l,我使用k-pointer为它分配内存.

c struct list

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

标签 统计

c ×1

list ×1

struct ×1