问题描述
- 这段编程出现了这个问题,哪位大神能帮我详细解答一下,谢谢啦
-
问题:0x01054259 处有未经处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
代码:
#include
using namespace std;
int main(){
void swap(int *,int *);
int *p1=NULL,*p2=NULL;
swap(p1,p2);
cout<<*p1<<" "<<*p2<<endl;
return 0;}
void swap(int *p11,int *p22)
{
int a=3,b=4;
p11=&a;
p22=&b;
}
解决方案
void swap(int *,int *); 你把函数声明放到main()函数上面。
解决方案二:
#include "stdafx.h"
#include
#include
using namespace std;
int main(int argc, char* argv[])
{
printf("Hello World!n");
void swap(int ,int *);
int *p1=NULL,*p2=NULL;
p1 = (int)malloc(sizeof(int));
p2 = (int*)malloc(sizeof(int));
swap(p1,p2);
cout<<*p1<<" "<<*p2<<endl;
return 0;
}
void swap(int *p11,int *p22)
{
int a=3,b=4;
*p11=a;
*p22=b;
}
时间: 2024-09-17 04:46:40