在C中设置指向NULL的指针,而不是编译

use*_*698 2 c null pointers

出于某种原因,当我尝试编译我的代码时,.exe文件在完成后就消失了......没有任何错误或警告.

这就是我的代码:

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

typedef struct student_ 
{
    int matnum;
    char vorname[20];
    struct student_ *next;
} student;

int main (int argc, char **argv) 
{
    student hans;
    hans.matnum = 12;

    student peter;
    peter.matnum = 13;
    peter.next = NULL; // THIS PART CAUSES MY PROBLEM

    hans.next = &peter;

    student *curr = &hans;
    while(curr != NULL)
    {
        printf("matnum: %d\n", (*curr).matnum);
        curr = curr->next;
    }

    return 0; 
}
Run Code Online (Sandbox Code Playgroud)

我想要它做的是迭代curr并将其设置为下一次每次curr已经不是NULL.因此,如果next为NULL,则while循环应该停止.

peter.next = NULL; // THIS PART CAUSES MY PROBLEM
Run Code Online (Sandbox Code Playgroud)

这就是我想要实现的目标,但它不起作用.:\


来自评论:

我没有收到错误.在我输入"gcc -Wall -o test test.c"后,test.exe会在那里停留一段时间然后被删除.

Dav*_*nan 6

对此最合理的解释是您的防病毒软件正在删除可执行文件.你的程序在这里编译并运行正常.

无论出于何种原因,可疑行会导致您的防病毒软件与已知病毒匹配的编译代码.当您删除该行时,它不再与病毒匹配,但当然程序失败.

暂时禁用您的防病毒以确认此假设.