小编Vai*_*ain的帖子

C++ 程序在使用 if 条件检查指针是否为 NULL 时崩溃

我正在尝试将队列上的 C 程序作为链表。每当我尝试执行时,只要遇到 if 条件将指针(在本例中为 q->f)与 NULL 进行比较,它就会崩溃。请检查以下代码:

#include<stdio.h>
using namespace std;
struct node
{
    int info;
    node *next;
};
struct que
{
    struct node *f; //front
    struct node *r; //rear
    que()
    {
        f=r=NULL; //initialize as NULL
    }
};
struct que *pq;
/* prototypes */
void disp(struct que *q);
int emp(struct que *q);
void ins(struct que *q,int x);
void del(struct que *q);

int main()
{
    int cho;
    while(1)    //so that it executes continuously and I can exit whenever I want …
Run Code Online (Sandbox Code Playgroud)

c++ null pointers if-statement

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

标签 统计

c++ ×1

if-statement ×1

null ×1

pointers ×1