Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 不知道nullptr,为什么我不应该';当我初始化队列列表时,不要使用nullptr_C_Data Structures - Fatal编程技术网

C 不知道nullptr,为什么我不应该';当我初始化队列列表时,不要使用nullptr

C 不知道nullptr,为什么我不应该';当我初始化队列列表时,不要使用nullptr,c,data-structures,C,Data Structures,我想为我的学校工作制作一个信息亭程序。当我编译它时,它不会发出任何错误的信号。但是当我尝试初始化我的队列列表时,它说我不能使用nullptr。。。我不明白我的代码出了什么问题 typedef struct { int data; struct Node* link; }Node; typedef struct { Node* front; Node* rear; }QueueTypeNode; QueueTypeNode* init_node(QueueTyp

我想为我的学校工作制作一个信息亭程序。当我编译它时,它不会发出任何错误的信号。但是当我尝试初始化我的队列列表时,它说我不能使用nullptr。。。我不明白我的代码出了什么问题

typedef struct
{
    int data;
    struct Node* link;
}Node;

typedef struct
{
    Node* front;
    Node* rear;
}QueueTypeNode;

QueueTypeNode* init_node(QueueTypeNode* head)
{
    head->front= NULL;
    head->front->link = head->rear;
    head->rear = NULL;

    return head;
}
这是错误的:

head->front= NULL;
head->front->link = head->rear;

head->front
指定为NULL,然后通过访问
head->front->link
立即取消对NULL指针的引用。您不能这样做,因为这会导致未定义的行为,并且可能会给您带来正在观察的运行时错误。

OT:您显示的代码没有定义
struct Node
。因此,它将不会编译。如果你使用的是<代码> NulLPTR < /C>,你使用的是C++构造——而C编译器拒绝它是不合理的。您的代码没有显示任何使用
nullptr
;它使用了<代码> null <代码>,C(C++中的)很好,但是它有点过时了。如果我想创建一个连接列表类型,那么我应该修复什么?