首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

用VC编译时出现0xC0000005:Access Violation异常

2013-03-13 
用VC编译时出现0xC0000005:Access Violation错误下面是程序,哪里错了呢?#include stdio.hint a[10]{0}

用VC编译时出现0xC0000005:Access Violation错误
下面是程序,哪里错了呢?
#include <stdio.h>
int a[10]={0};

void re(int i,int score)
{

if(score==100)
{
for(int j=0;j<10;j++)
printf("%d",a[j]);
}

a[i]=1;
score=2*score;
re(i+1,score);
score=score/2;
a[i]=0;
score=score-i-1;
if(score==100)
for(int j=0;j<10;j++)
printf("%d",a[j]);
re(i+1,score);
}

int main()
{
re(0,10);
return 0;
}
求大侠解答
[解决办法]
(1)你的代码,看不懂你想干嘛。
(2)int a[10]={0};
数组只定义了10个长度,但是你的程序是递归的,
执行过程中 用到了a[11],a[12],a[13]...,这是很危险的,violation的意思也可以翻译成强奸,你强奸了不是你分配的内存。
(3)你可能应该在a[10]以后,在出现a[11]访问前结束你的程序。

void re(int i,int score)
{

if (i>10)
{
return;
}
...省略...
}

热点排行