VC++中循环i为什么总是0而不递增啊

来源:百度知道 编辑:UC知道 时间:2024/06/11 10:14:59
请高手指教:为什么循环后,i总是=0啊,可我的循环里i最小=1啊????
#include <iostream.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>

int main()
{
int i;
double a[]={0};
double ramcustinterval[]={0};
for(i=1;;i++)
{
srand((unsigned)time(NULL));
double ran;
ran=rand()/32767.0;
ramcustinterval[i]=floor(-60*log(ran)/2);
a[i]=a[i-1]+ramcustinterval[i];
cout<<i<<":"<<a[i]<<endl;
if(a[i]>3361)
return 0;

}
return 0;
};

请高手指教:为什么输出
0:30
0:30
0:30
0:30
0:30
0:30
0:30
0:30




把for里面的return 0去掉再试.
如果是用的TC,没有必要用
int main()
{
return 0;
}
直接用
main()
{}

a[]和ramcustinterval[]数组大小仅仅为1
for循环里面,下标越界,i值大于数组大小
由于VC编译器不做越界检查,所以编译通过,但会输出一些意想不到的东西,在g++编译器中也是,不过运行时异常中断