关于越界的问题
#include<stdio.h>#include<conio.h>
void main()
{
float max,total=0;
float average;
int i,n=0;
struct stu
{
int num;
char *name;
char sex;
float score;
}boy[]={
{101,"li ping",'M',45},
{102,"zhang ping",'M',62.5},
{103,"he fang",'F',97.5},
{104,"cheng ling",'F',87},
{105,"wang ming",'M',58},
/*{106,"",'F',0},*/
};
max=boy[0].score;
for(i=0;i<5;i++)
{
if(max<boy[i+1].score)
{
max=boy[i+1].score;
}
total+=boy[i].score;
if(boy[i].score<60)
{
n+=1;
}
}
printf("total=%f\n",total);
printf("average=%f\n",total/5);
printf("fail=%d\n",n);
printf("max=%f\n",max);
getch();
}
在for()中,当i=4时,boy[4+1]不是超出范围了吗?怎么不会出错呢?郁闷啊,
请教