一个关于数组赋值的小问题
#include<iostream.h>void main()
{
float a[5];
int b[5];
int i;
for(i=0;i<5;i++)
{
cin>>a[i];
}
for(i=0;i<=5;i++)
{
b[i]=a[i];
}
cout<<"a[5]="<<a[0]<<","<<a[1]<<","<<a[2]<<","<<a[3]<<","<<a[4]<<endl;
cout<<"b[5]="<<b[0]<<","<<b[1]<<","<<b[2]<<","<<b[3]<<","<<b[4]<<"\n";
}
运行结果:(前5行为cin输入数据)
100
2.5
7
-6
89
a[5]=0,2.5,7,-6,89
b[5]=100,2,7,-6,89
Press any key to continue
为什么a[0]与b[0]不等?为什么由前者赋值后者,而后者正确而前者不正确?