老是提示内存访问冲突是什么情况,求大神指教!

VC_CS VC_CS 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
编译器总出现如下提示,求指教!

0x01214FB6 处有未经处理的异常(在 创建链表.exe 中): 0xC0000005: 写入位置 0x00000000 时发生访问冲突。


#include "stdafx.h"
#include<iostream>

using namespace std;

struct list
{
int data;
struct list *next;
};
typedef struct list node;
typedef node *link;

int main()
{
link ptr,head=NULL;
int num,i;
ptr =(link)malloc(sizeof(node));
ptr =head;
cout <<"please enter 5 numbers\n";
for(i=0;i<=4;i++)
{
cin >> num;
ptr->data =num;
ptr->next =(link)malloc(sizeof(node));
if(i==4)
ptr->next =NULL;
else
ptr =ptr->next;
}
ptr =head;
while(ptr!=NULL)
{
cout <<"the vallue is \n" <<ptr->data;
ptr =ptr->next;
}
return 0;
}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
VC_CS
C++ 语言 65,214 成员 250,514 内容